akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define SZ(vvv) ((int)vvv.size())
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 1000 + 5, M = 5e4 + 9, INF = 1e9, MOD = 998244353;

void runtestcase() {
 	string str;
 	cin >> str;
	int q, type;
	char c;
	cin >> q;
	deque<char> a, b;
	bool revStr = 0;
	while(q--) {
		cin >> type;
		if(type == 2) {
			cin >> type >> c;
			if(type == 1) {
				if(!revStr)
					a.push_front(c);
				else
					b.push_back(c);
			} else {
				if(!revStr)
					b.push_back(c);
				else
					a.push_front(c);
			}
		} else {
			revStr = !revStr;
		}
	}
	if(revStr) {
		reverse(b.begin(),b.end());
		for(char it: b)
			cout << it;
		reverse(str.begin(),str.end());
		cout << str;
		reverse(a.begin(),a.end());
		for(char it: a)
			cout << it;
	} else {
		for(char it: a)
			cout << it;
		cout << str;
		for(char it: b)
			cout << it;
	}
}


int main() {
    fastIO;
#ifdef LOCAL
    freopen("input.in", "rt", stdin);
//    freopen("cache.out", "wt", stdout);
#endif
  int t = 1, tt = 1;
//	cin >> t;
  while(t) {
//		cout << "Case #" << tt << ':' << ' ';
    runtestcase();
		cout << '\n';
    --t, ++tt;
  }
}


Measured memory_bytes: 3748
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
//		 static int mod =  (int) (Math.pow(10,9)+7);
		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
	    public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();

	        String[] S = new String[N];
	        int[][] minlast = new int[N][4];
	        for (int i=0 ; i<N; i++) {
	            S[i] = sc.next();
	            char[] c = S[i].toCharArray();
	            int now =0;
	            for(int j=0;j<S[i].length();j++) {
	            	if(c[j]=='(') {
	            		now++;
	            	} else {
	            		now--;
	            		minlast[i][0] = Math.min(minlast[i][0], now);
	            	}
	            }
	            minlast[i][1]=now;
	            minlast[i][2]=minlast[i][0]-now;
	        }
	        Arrays.sort(minlast, (b, c) -> Integer.compare(b[0], c[0]));
	        boolean[] used = new boolean[N];
	        int now1 = 0;
	        for(int i=N-1;i>=0;i--) {
	        	if(minlast[i][1]>0) {
	        		if(now1+minlast[i][0]<0) {
	        			System.out.println("No");
	        			return;
	        		}
	        		now1=now1+minlast[i][1];
	        	}
	        }
	        
	        for(int i=0;i<N;i++) {
	        	if(minlast[i][1]==0) {
	        		if(now1+minlast[i][0]<0) {
	        			System.out.println("No");
	        			return;	        			
	        		}
	        		now1=now1+minlast[i][1];
	        	}
	        }
	        Arrays.sort(minlast, (b, c) -> Integer.compare(b[2], c[2]));
	        int now2 = 0;
	        for(int i=N-1;i>=0;i--) {
	        	if(minlast[i][1]<0) {
	        		if(now2+minlast[i][2]<0) {
	        			System.out.println("No");
	        			return;	        			
	        		}
	        		now2=now2-minlast[i][1];
	        	}
	        }
	        

	        if(now1==now2) {
	        	System.out.println("Yes");
	        } else {
	        	System.out.println("No");
	        }

	    }
	    
	    

	}

Measured memory_bytes: 180176
n=int(input())
a=[0]*60003
for i in range(1,99):
    for j in range(i,100):
        for k in range(j,101):
            if i==j and j==k:
                l=6*k**2
                a[l]+=1
            elif i!=j and j!=k:
                l=i**2+j**2+k**2+i*j+j*k+k*i
                a[l]+=6
            else:
                l=i**2+j**2+k**2+i*j+j*k+k*i
                a[l]+=3

for i in range(n):
    print(a[i+1])
            

Measured memory_bytes: 9480
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>

#include<stdio.h>
#include<stdlib.h>

#define ll long long

using namespace std;

int main(){
    int X,t;
    cin >> X >> t;
    if(X<t){
        cout << 0 << endl;
    }
    else{
        cout << X-t << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
  #include <bitset>
  #include <complex>
  #include <deque>
  #include <exception>
  #include <fstream>
  #include <functional>
  #include <iomanip>
  #include <ios>
  #include <iosfwd>
  #include <iostream>
  #include <istream>
  #include <iterator>
  #include <limits>
  #include <list>
  #include <locale>
  #include <map>
  #include <memory>
  #include <new>
  #include <numeric>
  #include <ostream>
  #include <queue>
  #include <set>
  #include <sstream>
  #include <stack>
  #include <stdexcept>
  #include <streambuf>
  #include <string>
  #include <typeinfo>
  #include <utility>
  #include <valarray>
  #include <vector>
using namespace std;

int main(){
    ios:: sync_with_stdio(0);
    cin.tie(0);
    string input;
    int K;
    cin >> K;
    cin >> input;
    if (input.length() > K){
        input.erase(K, input.length());
        cout << input<< "...";
    } else{
        cout << input;
    }
    
    
    }


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,ll> P;
typedef vector<P> vip;

void solve(){
    int a,b;cin>>a>>b;
    cout << ceil((double)(a+b)/2)<<endl;
}

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


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

set<string> reg;

int main(){
  int n;

  while(cin >> n){
    reg.clear();

    for(int i = 0; i < n; i++){
      string s;
      cin >> s;
      reg.insert(s);
    }

    bool open = false;
    int m;
    cin >> m;

    while(m--){
      string s;
      cin >> s;

      if(reg.find(s) == reg.end()){
        cout << "Unknown " << s << endl;
      }
      else if(open){
        open = !open;
        cout << "Closed by " << s << endl;
      }
      else{
        open = !open;
        cout << "Opened by " << s << endl;
      }
    }
  }
}

Measured memory_bytes: 1236
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a + b) {
    	cout << min(k, a);
    } else {
    	cout << a - (k - a - b);
    }
}

Measured memory_bytes: 3656
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] groups={1,3,1,2,1,2,1,1,2,1,2,1};
        System.out.println(groups[sc.nextInt()-1]==groups[sc.nextInt()-1]?"Yes":"No");
    }
}

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

int main(){
        long long int n,m,a,b;
        bool Islanda[200010]={false},Islandb[200010]={false};

        cin>>n>>m;
        for(int i=0; i<m; ++i){
                cin>>a>>b;
                if(a==1) Islanda[b]=true;
                if(b==n) Islandb[a]=true;
        }

        for(int i=1; i<n; i++) {
                if(Islanda[i]&&Islandb[i]) {
                        cout<<"POSSIBLE"<<endl;
                        return 0;
                }
        }
        cout<<"IMPOSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 640
N = gets.to_i
A = []
answer = 0
for i in 0..N-1
    A[i] = gets.to_i
end

a = 0
answer = 0
B = A.sort

for i in 0..A.size-2

    if B[i] != B[i+1]

        if (i - a + 1) % 2 == 1

            answer += 1

        end

        a = i + 1

    end

end

if (A.size-a) % 2 == 1

    answer += 1

end



puts answer


Measured memory_bytes: 4676
//  A bug is never just a mistake. It represents something bigger. An error of thinking that makes you who you are.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAXN 500009
const int INF = 1.01e9;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl


int main(){
		
	ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    rep(i,0,2000){
    	int pp1 = i*0.08;
    	int pp2 = i*0.1;
    	if(pp1==a && pp2==b){
    		cout<<i<<"\n";
    		return 0;
    	}
    }
    cout<<"-1"<<"\n";

}

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

int main() {
    int n,m;
    cin >> n >> m;
    int x=1,y;
    for(int i=0;i<m;i++) x*=2;
    y=m*1900+(n-m)*100;
    cout << x*y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int64_t func(int64_t x){
  if(x%2!=0){return 0;}
  int64_t cnt=0;
  x/=2;
  while(x){
    cnt+=x/5;
    x/=5;
  }
  return cnt;
}
int main() {
 int64_t x;
 cin>>x;
 cout<<func(x)<<endl;
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define MAXN 2005
using namespace std;
using namespace __gnu_pbds;  

int n,x,y,cnt[MAXN],vis[MAXN],dist[MAXN];
vector<int> adj[MAXN];

void bfs(int s)
{
	vis[s]=1;
	dist[s]=0;
	queue<int> q;
	q.push(s);
	while(!q.empty())
	{
		int p=q.front();
		// cout<<p<<endl;
		q.pop();
		for(int i=0;i<adj[p].size();i++)
		{
			if(!vis[adj[p][i]])
			{
				dist[adj[p][i]]=min(dist[p]+1,dist[adj[p][i]]);
				// cout<<adj[p][i]<<" "<<
				vis[adj[p][i]]=1;
				q.push(adj[p][i]);
			}
		}
	}
	// for(int i=s+1;i<=n;i++) cout<<dist[i]<<" ";
	// cout<<endl;
	for(int i=s+1;i<=n;i++) cnt[dist[i]]++;
}

void solve()
{
	cin>>n>>x>>y;
	for(int i=1;i<=n-1;i++)
	{
		adj[i].pb(i+1);adj[i+1].pb(i);
	}
	adj[x].pb(y);adj[y].pb(x);
	for(int i=1;i<=n-1;i++)
	{
		for(int i=1;i<=n;i++)
		{
			vis[i]=0;
			dist[i]=INT_MAX;
		}
		bfs(i);
	}
	for(int i=1;i<=n-1;i++) cout<<cnt[i]<<endl;
}

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string N;

  cin >> N;

  if( ((N.at(0)==N.at(1))&&(N.at(1)==N.at(2))) || ((N.at(1)==N.at(2))&&(N.at(2)==N.at(3))) )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
    int n;cin>>n;
    string s,t;cin>>s;
    int ans=0;
    
    rep(i,10)rep(j,10)rep(k,10){
        t=s;
        int a = t.find(i+'0');
        if(a<=n && a>=0)t = t.substr(a+1);
        else break;
        
        int b = t.find(j+'0');
        if(b<=n-a && b>=0)t = t.substr(b+1);
        else break;

        int c = t.find(k+'0');
        if(c<=n-a-b && c>=0){
          ++ans;
//          cout<<i<<j<<k<<endl;
        }
    }
    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

ll dp[105][100010];

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

	int N, W;
	ll w[100], v[100];
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= W; j++) {
			if(i == 0 or j == 0) dp[i][j] = 0;
			else{
				if(w[i-1] > j) dp[i][j] = dp[i-1][j];
				else dp[i][j] = max(dp[i-1][j-w[i-1]]+v[i-1], dp[i-1][j]);
			}
		}
	}
	cout << dp[N][W] << endl;

	return 0;
}

Measured memory_bytes: 80128
N,M=map(int,input().split())
H=[list(map(int,input().split())) for _ in range(M)]
H.sort(key=lambda x:x[1])
b=H[0][1]
ans=1
for i in range(M):
    if H[i][0]>=b:
        ans+=1
        b=H[i][1]
print(ans)


Measured memory_bytes: 64616
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end() 
using namespace std;
//using pr = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言
//int myfunc(int, vvec);

//グローバル変数
//int N, M;
//vvec data(N, vec(M));

//関数：
int gcd(int mx, int mn) {
	if(mn == 0) return(mx);
	else gcd(mn, mx%mn);
}

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

	int N; cin >> N;
	int lg = sqrt(N);
	int cl = 1;
	for(int i=lg; i>=1; --i) {
		if(N % i == 0) {
			cl = i;
			break;
		}
	}

	int rw = N / cl;
	cout << (cl-1) + (rw-1) << endl;
	return 0;
}
//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(),v.end());
  double ans = v[0];
  for(int i = 1; i < n; i++) ans = (ans+v[i])/2;
  cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n,t;
  cin >> n >> t;
  int a[n];
  int b[n];
  int min = 10000;
  for(int i = 0;i <n;i++){
    cin >> a[i] >> b[i];
    if(b[i] <= t){
      if(min > a[i]){
        min = a[i];
      }
    }
  }
  if(min == 10000){
    cout << "TLE" << endl;
  }else{
    cout << min << endl;
  }
}


Measured memory_bytes: 256
import sys
from bisect import bisect_right, bisect_left
input = sys.stdin.readline
n, m, v, p = [int(x) for x in input().strip().split()]
araw = sorted([int(x) for x in input().strip().split()])
a = list(reversed(araw))

def f(x, n, m, v, p, a, araw):
    c = p - (n - bisect_right(araw, a[x-1]+m)) - 1
    if c < 0:
        return False
    vote = m * (v - 1)
    thr = a[x-1] + m
    for i, aa in enumerate(a, start=1):
        if vote <= 0:
            break
        if i == x:
            continue
        if aa > thr:
            vote -= m
        elif aa == thr:
            if c:
                vote -= m
                c -= 1
        elif thr - aa < m:
            if c:
                vote -= m
                c -= 1
            else:
                v_ = min(vote, thr - aa, m)
                vote -= v_
        else:
            vote -= m
    return vote <= 0

x = 0
l = 1
r = n + 1
while l < r:
    x = (l + r) // 2
    if f(x, n, m, v, p, a[:], araw):
        l = x + 1
    else:
        r = x
print(l-1)

Measured memory_bytes: 14260
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    ll N, K;
    cin >> N >> K;
    N %= K;
    cout << min(N, abs(N-K)) <<endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int K2[100008];

int main() {
    int N, K, Q, A;
    scanf("%d%d%d", &N, &K, &Q);
    for(int i=0; i<Q; ++i) {
        int A;
        scanf("%d", &A);
        K2[A-1] += 1;
    }
    for(int i=0; i<N; ++i) {
        printf(0<K-Q+K2[i] ? "Yes\n" : "No\n");
    }
    return 0;
}


Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static BufferedReader br;
    static PrintWriter out;
    static StringTokenizer st;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));

        out.println(solve(nextInt()));

        out.close();
    }

    static long solve(int k) {
        long[] lunluns = new long[100005];
        for (int i = 1; i < 10; i++) lunluns[i-1] = i;
        int slow = 0;
        int fast = 9;

        while (fast <= k - 1) {
            long last = lunluns[slow] % 10;
            long num = lunluns[slow] * 10;

            if (last != 0) {
                lunluns[fast] = num + last - 1;
                fast++;
            }
            lunluns[fast] = num + last;
            fast++;
            if (last != 9) {
                lunluns[fast] = num + last + 1;
                fast++;
            }
            slow++;
        }
        out.println();

        return lunluns[k-1];
    }


    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static char nextCharacter() throws IOException {
        return next().charAt(0);
    }

    static String nextLine() throws IOException {
        return br.readLine().trim();
    }
}


Measured memory_bytes: 21332
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	long double r;cin >> r;
	long double pi = 2 * acos(0), area = pi * r * r , peri = 2 * pi * r;
	cout << fixed << setprecision(10) << area << " " << peri << "\n";
	return 0;
}



Measured memory_bytes: 3320
N,M = map(int, input().split())
P = list(map(int, input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
uf = UnionFind(N+1)
for _ in range(M):
  x,y = map(int, input().split())
  uf.union(x,y)
  
ans = 0
for i in range(N):
  if uf.same(i+1, P[i]):
    ans += 1
      
print(ans)

Measured memory_bytes: 84680
#include <array>
  #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 <deque>
  #include <complex>
  #include <stack>
  #include <queue>
  #include <cstdio>
  #include <cctype>
  #include <cstring>
  #include <ctime>
  #include <iterator>
  #include <bitset>
  #include <numeric>
  #include <list>
  #include <iomanip>
  using namespace std;


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

  typedef vector<int> vint;
  typedef vector<vector<int> > vvint;
  typedef vector<long long> vll, vLL;
  typedef vector<vector<long long> > vvll, vvLL;

  #define VV(T) vector<vector< T > >

  template <class T>
  void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
  }

  template <class F, class T>
  void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
  }


  #define REP(i,n) for(int i=0;i<int(n);++i)
  #define ALL(v) (v).begin(),(v).end()
  #define RALL(v) (v).rbegin(),(v).rend()
  #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
  #define PB push


  #define MOD 1000000007LL
  #define EPS 1e-10

  struct UnionFind
  {
    vector< int > data;

    UnionFind(int sz)
    {
      data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
      x = find(x), y = find(y);
      if(x == y) return(false);
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
      return(true);
    }

    int find(int k)
    {
      if(data[k] < 0) return(k);
      return(data[k] = find(data[k]));
    }

    int size(int k)
    {
      return(-data[find(k)]);
    }

    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
  };

  double dp[3010][3010];

  int main()
  {
    int N;
    cin >> N;
    vector<double> p(N);
    REP(i, N) cin >> p[i];

    dp[0][0] = 1.0;
    
    REP(i, N)
    {
      REP(j, N + 1)
      {
        if (j > 0)
        {
          dp[i + 1][j] += dp[i][j - 1] * p[i];
        }
        dp[i + 1][j] += dp[i][j] * (1 - p[i]);
      }
    }

    double ans = 0.0;
    REP(j, N + 1)
    {
      if (j * 2 >= N)
      {
        ans += dp[N][j];
      }
    }
    printf("%.10lf\n", ans);
    return 0;
  }


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=9;++i){
        for(int j=1;j<=9;++j){
            if(i*j==n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 768
#include<stdio.h>
int main(){
  int n[10000],i,j;

  for(i=0;i<10000;i++){
    scanf("%d",&n[i]);
    if(n[i] == 0) break;
  }
  for(j=0;j<i;j++){
    printf("Case %d: %d\n",j+1,n[j]);
  }
  return 0;
}





Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];
    bool allodd = true;
    ll oddcnt = 0, sum = 0;
    rep(i,N){
        sum += A[i];
        if(A[i]%2){
            oddcnt++;
        }else{
            allodd = false;
        }
    }
    ll m = *min_element(all(A));

    cout << ( (sum%2) || (sum%2==0&&N%2==0&&m%2) ? "First" : "Second") << endl;
}


Measured memory_bytes: 4428
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int N = 1e6+5;
const double eps = 1e-8;

string a,b,now;
int x,y;
int main(){
  cin>>now;
  for(int i = 1;i <= now.size();i++) cout<<"x";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
/*  CREATED BY
    STREAM_CIPHER
    7-aug-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        int n;
        cin>>n;
        vector<int>a(n);
        for(auto &i:a)
            cin>>i;
        int dp[n+1];
        memset(dp,inf,sizeof dp);
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        for(int i=2;i<n;i++)
        {
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        }
        cout<<dp[n-1]<<endl;
}

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

int main() {
	int N,K;
  	cin >> N >> K;
  
  	int ans = K;
  	if(N == 1) {
    	cout << ans << endl;
    }else {
  	for(int i = 0; i < N - 1; i++) {
    	ans *= (K - 1);
    }
  
  	cout << ans << endl;
    }
}

Measured memory_bytes: 256
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
const int MAXN = 100005;
ll mod=1000000007;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vi a(n);
	rep(i,0,n-1){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	ll sum = 0;
	rep(i,0,n-2){
		if(a[i]<0 and a[i+1] < 0){
			a[i] = -a[i];
			a[i+1] = -a[i+1];
		}
		else if(a[i] > 0 and a[i+1] < 0){
		}
		else if(-a[i] > a[i+1]){
			a[i] = -a[i];
			a[i+1] = -a[i+1];
		}
	}
	rep(i,0,n-1){
		sum+=a[i];
	}
	cout<<sum<<nl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {

    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;

    string R;
    for (int i = 0; i < N; ++i) {
        R += S[i];
        R += T[i];
    }

    cout << R << endl;

    return 0;

}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int num = i;
    int sum = 0;
    while (num != 0) {
      sum += num%10;
      num /= 10;
    }
    if (a <= sum && sum <= b) {
      ans += i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
bool fin = false;

int search(vector<int> xx, vector<int> ans){
    // int check = 1;
    // bool flag = false;
    for(int i = 1; i < xx.size(); i++){
        if(xx.at(i) > i){
            cout << -1 << endl;
            fin = true;
            return 0;
        }
    }
    if(xx.size() == 1){
        for(int i = ans.size()-1; i >= 0; i--){
            cout << ans.at(i) << endl;
        }
        fin = true;
        return 0;
    }
    for(int i = xx.size()-1; i >0 ; i--){
        if(fin){
            return 0;
        }
        if(xx.at(i) == i){
            //erase
            // flag = true;
            vector<int> new_xx = xx;
            new_xx.erase(new_xx.begin() + i);

            ans.push_back(i);
            search(new_xx, ans);
            // check *= search(new_xx, ans);
            ans.pop_back();
        }
    }
    return 0;
}

int main(){
    cin >> N;
    vector<int> b = vector<int>(N+1);
    for(int i = 1; i<N+1; i++){
        cin >> b.at(i);
    }
    vector<int> ans;
    search(b, ans);
    if(fin == false){
        cout << -1 << endl;
    }
    return 0;
}



Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define fi first
//#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;

  if (S == U) A--;
  else if (T == U) B--;

  cout << A << ' ' << B;
}
#endif


Measured memory_bytes: 256
#include <stdio.h>

#define WIDTH 10
#define HEIGHT 10

int field[ WIDTH + 4 ][ HEIGHT + 4 ];
const int dx[ 3 ][ 4 ] = { { -1, 0, 1, 0 }, { -1, 1, -1, 1 }, { -2, 0, 2, 0 } };
const int dy[ 3 ][ 4 ] = { { 0, -1, 0, 1 }, { -1, -1, 1, 1 }, { 0, -2, 0, 2 } };

int main( void ) {
	int i, x, y, size, white, max;

	while ( scanf( "%d,%d,%d", &x, &y, &size ) == 3 ) {
		x += 2;
		y += 2;

		field[ x ][ y ]++;

		while ( size-- )
			for ( i = 4; i--; field[ x + dx[ size ][ i ] ][ y + dy[ size ][ i ] ]++ ) ;				
	}

	white = max = 0;
	for ( y = 2; y < HEIGHT + 2; y++ )
		for ( x = 2; x < WIDTH + 2; x++ )
			if ( !field[ x ][ y ] )
				white++;
			else if ( max < field[ x ][ y ] )
				max = field[ x ][ y ];

	printf( "%d\n%d\n", white, max );

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  double t,x;
  cin>>t>>x;
  printf("%.10f\n", t/x);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <set>
#include <stdio.h>

using namespace std;

int n, t, l, b;
set<int> setL, setB;
double dp[105][105];

int main(void)
{
  while(1){
    cin >> n >> t >> l >> b;
    if(n == 0) break;
    int x;
    setL.clear(), setB.clear();
    for(int i = 1; i <= l; i++){
      cin >> x;
      setL.insert(x);
    }
    for(int i = 1; i <= b; i++){
      cin >> x;
      setB.insert(x);
    }

    for(int i = 0; i <= t; i++){
      for(int j = 0; j <= n; j++){
        dp[i][j] = 0;
      }
    }
    dp[0][0] = 1;

    for(int i = 0; i < t; i++){
      for(int j = 0; j < n; j++){
        for(int k = 1; k <= 6; k++){
          int nj = j + k;
          if(nj > n) nj = n - (nj-n);

          int ni = i+1;
          if(setB.count(nj)) nj = 0;
          else if(setL.count(nj)) ni++;

          if(ni <= t) dp[ni][nj] += dp[i][j] / 6;
        }
      }
    }

    double ans = 0;
    for(int i = 0; i <= t; i++) ans += dp[i][n];
    printf("%.11f\n", ans);
  }

  return 0;
}



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

using namespace std;

int main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  sort(v.begin(),v.end(),greater<int>());
  int ans=0;
  for(int i=0;i<v.size();i++){
    if(i==0 || i%2==0){
      ans+=v[i];
    }else{
      ans-=v[i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long lli;

int main() {
	lli n,m,d;
	scanf("%lld%lld%lld",&n,&m,&d);
	printf("%.10lf\n",(d==0 ? 1.0 : 2.0)*(n-d)/(n*n)*(m-1));
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		if(n%2==0) {
			System.out.println(n);
		}
		else {
			System.out.println(n*2);
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
// ifstream fin("filename.in");
// ofstream fout("filename.out");

int main(){
	ll n;
	cin>>n;
	vector<ll> a(n);
	ll i,j;
	for(i=0;i<n;i++)
		cin>>a[i];
	ll money = 1000,stock = 0,stock2 = 0;
	for(i=0;i<n-1;i++)
	{
		if(a[i]<a[i+1])
		{
			stock = money/a[i];
			money = money - stock*a[i];
			stock2 = stock+stock2;
		}
		else
		{
			money = money+stock2*a[i];
			stock2 = 0;
		}
	}
	cout<<money+stock2*a[i];
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        for (int i=0;i<N;i++) {
            A[i] = Integer.parseInt(sc.next());
            if (map.containsKey(A[i])) {
                map.put(A[i], map.get(A[i])+1);
            } else {
                map.put(A[i], 1);
            }
        }

        int ans = 0;
        while (!map.isEmpty()) {
            int kk = map.lastKey();
            if (map.get(map.lastKey())>1) {
                map.put(map.lastKey(), map.get(map.lastKey())-1);
            } else {
                map.remove(map.lastKey());
            }
            String ss = Integer.toBinaryString(kk);
            // System.out.println((long)Math.pow(2, ss.length())-kk);
            int val = (int)((long)Math.pow(2, ss.length())-kk);
            if (map.containsKey(val)) {
                if (map.get(val)>1) {
                    map.put(val, map.get(val)-1);
                } else {
                    map.remove(val);
                }
                ans++;
            }
        }
        // System.out.println(map);
        System.out.println(ans);
    }
}

Measured memory_bytes: 71256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>

#define REP(i,n) for(int i = 0; i < (n); i++)
#define REPC(x,c) for(auto x:(c))
#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << max(max(a + b, a*b), a - b) << endl;
}

Measured memory_bytes: 256
t=raw_input()
#t=t.replace('eraser','').replace('dreamer','').replace('erase','').replace('dream','')
while len(t):
    if len(t)>10 and t[:11]=='dreameraser':
        t=t[11:]
    elif len(t)>9 and t[:10]=='dreamerase':
        t=t[10:]
    elif len(t)>6 and t[:7]=='dreamer':
        t=t[7:]
    elif len(t)>4 and t[:5]=='dream':
        t=t[5:]
    elif len(t)>5 and t[:6]=='eraser':
        t=t[6:]
    elif len(t)>4 and t[:5]=='erase':
        t=t[5:]
    else:
        break
print 'YES' if t=='' else 'NO'

Measured memory_bytes: 2820
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[1000];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    double s=arr[0];
    for(int i=1;i<n;i++)
    {
         s=(s+arr[i])/2;
    }
    cout<<setprecision(7)<<fixed<<s<<endl;
}


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

int main() {
   int n;
   cin >> n;
   int ac =0;
   int wa =0;
   int tle =0;
   int re =0;
   for (int i = 0; i < n; i++) {
       string a;
       cin >> a;
       if(a=="AC")ac++;
       else if(a=="WA")wa++;
       else if(a=="TLE")tle++;
       else re++;
   }
   cout <<"AC x "<<ac<<endl;
   cout <<"WA x "<<wa<<endl;
   cout <<"TLE x "<<tle<<endl;
   cout <<"RE x "<<re<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	vector<int> a(5);
	for (auto& x : a) cin >> x;
	for (int i = 0; i < 5; ++ i) {
		if (a[i] == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3620
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 12

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	cout << fixed;
	cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int n;
	cin >> n;
	
	vector<int> p, q;
	for (int i = 0; i < n; i++)
	{
		int input;
		cin >> input;
		p.push_back(input);
	}
	for (int i = 0; i < n; i++)
	{
		int input;
		cin >> input;
		q.push_back(input);
	}
	
	vector<int> permutation;
	for (int i = 0; i < n; i++)
	{
		permutation.push_back(i + 1);
	}
	
	int counter = 0;
	int p_counter, q_counter;
	do
	{
		counter++;
		
		if (permutation == p)
		{
			p_counter = counter;
		}
		
		if (permutation == q)
		{
			q_counter = counter;
		}
	}
	while(next_permutation(permutation.begin(), permutation.end()));
	
	cout << abs(p_counter - q_counter) << endl;

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


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

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n), ys(n);
    for (auto& x : xs) std::cin >> x;
    for (auto& y : ys) std::cin >> y;

    // A中の最右位置、B中の最左位置を求める
    std::vector<int> xr(n + 1, -1), yl(n + 1, -1);
    for (int i = 0; i < n; ++i) xr[xs[i]] = i;
    for (int i = n - 1; i >= 0; --i) yl[ys[i]] = i;

    // 最大のシフト幅を求める
    int d = 0;
    for (int i = 1; i <= n; ++i) {
        if (xr[i] == -1 || yl[i] == -1) continue;
        d = std::max(d, xr[i] - yl[i] + 1);
    }

    // シフトする
    std::rotate(ys.begin(), ys.begin() + n - d, ys.end());

    // 被り判定
    for (int i = 0; i < n; ++i) {
        if (xs[i] == ys[i]) {
            std::cout << "No\n";
            return;
        }
    }

    std::cout << "Yes\n";
    for (auto y : ys) std::cout << y << " ";
    std::cout << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 6360
#include<iostream>

using namespace std;

int n, mini=1000000, maxi=-100000, x;

int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> x;
		mini=min(mini, x);
		maxi=max(maxi, x);
	}
	cout << maxi-mini << endl;
	return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

struct DisjointSet{
    vector<int> rank, p;

    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        rep(i, size) makeSet(i);
    }

    void makeSet(int x){
        rank[x] = 0;
        p[x] = x;
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }

    int findSet(int x){
        if(p[x] == x) return x;
        p[x] = findSet(p[x]);        
        return p[x];
    }

    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        } else {
            p[x] = y;
            if(rank[x] == rank[y]) rank[y]++;
        }
    }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    DisjointSet ds(N);
    rep(i, Q){
        int com, x, y;
        cin >> com >> x >> y;
        if(com) cout << ds.same(x, y) << endl; 
        else ds.unite(x, y);
    }
}


Measured memory_bytes: 3176
class Array
  def lcm
    self.inject(:lcm)
  end

  def gcd
    self.inject(:gcd)
  end
end

n = gets.to_i
arr = gets.chomp.split(" ").map(&:to_i)

f = 0
lcm = arr.lcm - 1

arr.each do |num|
  f += lcm % num
end

puts f

Measured memory_bytes: 20604
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;

const long long INF = 2e18 + 18;

struct Block {
	int weight, solidness, value;
	Block() {;}
	Block(int w, int s, int v) {
		weight = w;
		solidness = s;
		value = v;
	}	
};

bool cmp(Block b1, Block b2) {
	return b1.weight + b1.solidness < b2.weight + b2.solidness;
}

vector<Block> b;
vector<long long> dp;

void solve() {
	int n; cin >> n;
	b.resize(n);
	int maxs = 2e4 + 4;
	for (int i = 0; i < n; i++) {
		int w, s, v;
		cin >> w >> s >> v;
		b[i] = Block(w, s, v);
	}
	sort(b.begin(), b.end(), cmp);
	dp.resize(maxs + 1);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int w = min(maxs - b[i].weight, b[i].solidness); w >= 0; w--) {
			dp[w + b[i].weight] = max(dp[w + b[i].weight], dp[w] + b[i].value);
		}
	}
	long long ans = 0;
	for (int i = 0; i <= maxs; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define int int64_t
#define watch(x) cout << (#x) << " is " << (x) << endl

const int32_t MAX=1e9+7;
typedef vector<int> vi;
typedef vector<int64_t> vll;

int32_t main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed;

    //Problem code start

    int n,x,t;
    cin >> n >> x >> t;
    int ans{0};
    ans+=((n/x)*t);
    if(n%x!=0)
        ans+=t;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3644
class Node:
    def __init__(self, parent, left, right):
        self.parent = parent
        self.left = left
        self.right = right

def preParse(u):
    if u ==-1:
        return
    print(" %d"%(u),end = "")
    # print(u,end=' ')
    preParse(Nodes[u].left)
    preParse(Nodes[u].right)

def inParse(u):
    if u ==-1:
        return
    inParse(Nodes[u].left)
    print(" %d"%(u),end = "")

    # print(u,end=' ')
    inParse(Nodes[u].right)

def postParse(u):
    if u ==-1:
        return
    postParse(Nodes[u].left)
    postParse(Nodes[u].right)
    # print(u,end=' ')
    print(" %d"%(u),end = "")



def decode_node_data(n):
    '''
    n...受け取る文字列、一行ずつ
    一行ずつ、文字列からノードに変化する
    '''
    global Nodes
    num_of_elem = len(n)
    if num_of_elem < 2:
        raise ValueError
    elif num_of_elem == 2:  # leaf
        pass

    else:
        id, left,right = list(map(int,n))
        # まず、一人目の子供をとりあえず左に格納する
        Nodes[id].left = left
        if left!=-1:
            Nodes[left].parent=id
        
        Nodes[id].right = right
        if right !=-1 :
            Nodes[right].parent=id


MAX_NODES = 100001
Nodes = [Node(-1, None, None) for _ in range(MAX_NODES)]
if __name__ == "__main__":

    num_of_nodes = int(input())
    node_data = []
    for _ in range(num_of_nodes):
        node_data.append(input().split(' '))

    for n in node_data:
        decode_node_data(n)
    
    for i in range(num_of_nodes):
        if Nodes[i].parent==-1:
            root=i
    
    print('Preorder')
    preParse(root)
    print()
    
    print('Inorder')
    inParse(root)
    print()
    
    print('Postorder')
    postParse(root)
    print()





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

using namespace std;

const int MOD = 1e9 + 7;


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

    int n, a;

    cin >> n >> a;

    if (n <= 5) {
        cout << 0;
        return 0;
    }
    if (n <= 12) {
        cout << a/2;
        return 0;
    }
    cout << a;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    vector<int> e2w(n + 2, 0), w2e(n + 2, 0);
    for (int i = 1; i <= n; i++) {
        if (s[i - 1] == 'E') {
            e2w[i]++;
        } else {
            w2e[i]++;
        }
    }

    for (int i = 1; i <= n; i++) {
        e2w[n - i + 1] += e2w[n - i + 2];
        w2e[i] += w2e[i - 1];
    }

    int res = 1000000000;
    for (int i = 1; i <= n; i++) {
        if (res > e2w[i + 1] + w2e[i - 1]) {
            res = e2w[i + 1] + w2e[i - 1];
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 3076