akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll const INF = 1e18;


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

int n;
cin >> n;
vl a(n);
rep(i,n) cin >> a[i];

rep(i,n) {
    if(a[i] == 0) {
        cout << 0 << endl;
        return 0;
    }
}
__int128_t ans = 1;
rep(i,n) {
    ans *= a[i];
    if(ans > INF) {
        cout << -1 << endl;
        return 0;
    }
}
cout << (ll)ans << endl;
return 0;
}

Measured memory_bytes: 3996
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	data = input[0].split(' ').map(x=>parseInt(x));
	console.log(data[0]*(data[0]-1)/2 + data[1]*(data[1]-1)/2);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int n;
  cin >> n;
  std::vector<int> p(n);
  std::vector<int> q(n);
  rep(i,n) cin >> p.at(i);
  rep(i,n) cin >> q.at(i);
  std::vector<int> a(n);
  rep(i,n) a.at(i) = i+1;
  map<std::vector<int>, int> mp;
  do {
    mp[a] = mp.size();
  } while (next_permutation(a.begin(),a.end()));
  int ans = abs(mp[p] - mp[q]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8684
import numpy as np
N = int(input())
a = input().split()
b = 0
c = []
for i in range(N):
  b = b + int(a[i])
  c.append(b)
d = c[-1]
e = []
for j in range(N):
  e.append(2*c[j] - d)
f = np.abs(e)
f.sort()
print(f[0])

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

int main()
{
    int n,k,q,ans=0;
    cin>>n>>k>>q;
    int a[n]={};
    for(int i=0;i<q;i++)
    {
        int x;
        cin>>x;
        a[x-1]++;
    }
    for(int i=0;i<n;i++)
      {
         if((a[i]+k-q)>0)
         cout<<"Yes\n";
         else
            cout<<"No\n";
      }
    return 0;
}



Measured memory_bytes: 3888
import math

# N = 5
# N = 10
# N = 10000000007
# car = [3, 2, 4, 3, 5]
# car = [123, 123, 123, 123, 123]
# car = [2, 3, 5, 7, 11]
# tmp = [N, 0, 0, 0, 0]

N = int(input())

car = []
for _ in range(5):
    car.append(int(input()))

car.sort()

min_num = car[0]

time = math.ceil(N / min_num) + 4

print(time)


Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

ll MODpow(ll n, ll m) {
    ll result = 1;
    while (m) {
        if (m % 2 == 1) {
            result *= n;
            result %= MOD;
        }

        m /= 2;
        n *= n;
        n %= MOD;
    }

    return result;
}

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

    const ll M = s.size();

    //dp[i][j] := キーをi回押して長さjの文字列を作る方法の数
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));
    dp[0][0] = 1;
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            //'0'or'1'を押す
            (dp[i + 1][j + 1] += dp[i][j] * 2) %= MOD;

            //'B'を押す
            (dp[i + 1][max(j - 1, (ll)0)] += dp[i][j]) %= MOD;
        }
    }

    cout << dp[N][M] * MODpow(MODpow(2, M), MOD - 2) % MOD << endl;
}

Measured memory_bytes: 195840
/* ****GT_18**** */

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define INF			1000000000000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
using namespace __gnu_pbds;

#define N  200005

ll n,q;
set<pii> rows;
set<pii> cols;
bool rowused[N];
bool colused[N];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		cin>>n>>q;
		ll ans=0;
		rows.insert({n,n});
		cols.insert({n,n});
		while(q--){
			ll t,x;
			cin>>t>>x;
			if(t==1){
				if(colused[x])continue;
				colused[x]=1;
				auto it = cols.lower_bound({x,0});
				pii temp = *it;
				ll dep = temp.S;
				ans+=dep-2;
				rows.insert({dep,x});
			}
			else{
				if(rowused[x])continue;
				rowused[x]=1;
				auto it = rows.lower_bound({x,0});
				pii temp= *it;
				ll dep = temp.S;
				ans+=dep-2;
				cols.insert({dep,x});
			}
		}
		cout<<(n-2)*(n-2) - ans<<endl;

	}
	return 0;
}

Measured memory_bytes: 16412
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
#define INF 1e9
typedef long long LL;
const LL mod = 1e9+7;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int answer = min(A,B) + min(C,D);
  cout << answer << endl;
  
  return 0;
}

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

int main(){
	array<int,26> word = {};
	string str;
	while(getline(cin,str)){
		transform(str.begin(),str.end(),str.begin(),::tolower);
		for(int i = 0; i < str.length(); i++){
			if(str[i] >= 'a' and str[i] <= 'z'){
				str[i] = str[i] - 97;
				word[(int)str[i]] += 1;
			}
		}
	}
	char w = 'a';
	for(int i = 0; i < 26; i++){
		cout << char(w + i)  << " : " << word[i] << endl;
	}
}		 

Measured memory_bytes: 3180
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

ll N, K;

int main() {

	cin >> N >> K;

	ll ans = 0;

	rep(k, K) {
		ll A_1 = k + 1;
		vector<ll> divs;
		for (ll n = 1; n * n <= A_1; ++n)
			if (A_1 % n == 0) {
				divs.push_back(n);
				if (A_1 / n != n)
					divs.push_back(A_1 / n);
			}
		sort(all(divs));
		vector<ll> counts(divs.size());
		vector<ll> countspow(divs.size());

		for (ll i = divs.size() - 1; i >= 0; --i) {
			counts[i] = K / divs[i];
			ans += divs[i] * modpow(counts[i], N - 1, 1000000007);
			ans %= 1000000007;
			countspow[i] = modpow(counts[i], N - 1, 1000000007);
			for (ll j = i + 1; j < divs.size(); ++j) {
				if (divs[j] % divs[i] == 0) {
					countspow[i] -= countspow[j];
					ans -= divs[i] * countspow[j];
					ans %= 1000000007;
				}
			}
		}
		/*
		for (auto cc : counts) {
			ans += modpow(cc, N - 1, 1000000007);
			ans %= 1000000007;
		}*/

	}

	while (ans < 0) ans += 1000000007;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3672
use std::io;


fn main() {
    let s = read_one::<String>();
    println!("{} {}", &s[0..4], &s[4..]);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

using namespace std;

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

  for (int i = 1; i <= s.length(); i++) {
    if (i % 2 != 0) {
      cout << s[i - 1];
    }
  }
  cout << "" << endl;

  return 0;
}


Measured memory_bytes: 576
#include <iostream>
#include <vector>

using namespace std;

void counting_sort(vector<int>& v) {
    vector<int> count(10001, 0);
    vector<int> tmp(v.size());
    for (int i = 0; i < v.size(); ++i) {
        tmp[i] = v[i];
        ++count[v[i]];
    }

    for (int i = 1; i < count.size(); ++i)
        count[i] = count[i - 1] + count[i];

    for (int i = v.size() - 1; i >= 0; --i) {
        v[count[tmp[i]] - 1] = tmp[i];
        --count[tmp[i]];
    }
}

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

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

    counting_sort(a);

    cout << a[0];
    for (int i = 1; i < n; ++i)
        cout << ' ' << a[i];
    cout << '\n';
}



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


int main()
{
	int n;
	int *box;
	int *count;
	int max, num;
	int i, j;


	scanf("%d", &n);

	box = (int *)malloc(sizeof(int) * n);

	max = -1;
	for(i = 0; i < n; i++){
		scanf("%d", &box[i]);
		if(box[i] > max)
			max = box[i];
	}

	count = (int *)malloc(sizeof(int) * max + 1);
	for(i = 0; i <= max; i++)
		count[i] = 0;

	// 数値カウント
	for(i = 0; i < n; i++)
		count[box[i]]++;

	// 表示
	for(i = 0; i <= max; i++){
		num = count[i];
		if(num != 0){
			for(j = 0; j < num; j++){
				printf("%d", i);
				if(j != num - 1)
					printf(" ");
			}
			if(i != max)
				printf(" ");
		}
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 9592
#include<stdio.h>
int main()
{
    char s[5];
    int n,i;
    scanf("%s",s);
    n=700;
    for(i=0;i<3;i++)
    {
        if(s[i]=='o')
        {
            n=n+100;
        }
    }
    printf("%d\n",n);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#define MAX_LEN 10000

int array[MAX_LEN];

int main()
{
	int len;
	std::cin >> len;
	
	for(int i=0;i<len;i++)
	{
	    std::cin >> array[i];
	}

    // min
    int min=array[0];
    for(int i=1;i<len;i++)
	{
	    if(array[i]<min) min=array[i];
	}
	
    // max
    int max=array[0];
    for(int i=1;i<len;i++)
	{
	    if(array[i]>max) max=array[i];
	}
	
	// sum
	long sum=0;
    for(int i=0;i<len;i++)
	{
	    sum+=array[i];
	}
	
	printf("%d %d %ld\n",min,max,sum);
}


Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

string s;

int main() {
  cin >> s;

  bool ans;
  if (s.at(0) == s.at(1) && s.at(1) == s.at(2)) {
    ans = true;
  } else if (s.at(1) == s.at(2) && s.at(2) == s.at(3)) {
    ans = true;
  } else {
    ans = false;
  }

  cout << (ans ? "Yes" : "No") << endl;
}

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

int main(void){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if((A+B)>(C+D))cout<<"Left";
  else if((A+B)==(C+D))cout<<"Balanced";
  else cout<<"Right";
  return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))

typedef long long LL;

int main(){
  LL n,p,q;
  cin >> n >> p >> q;
  vector<LL> c(n);
  for(int i=0;i<n;i++){
    cin >> c[i];
    c[i]+=i*p;
  }
  sort(c.begin(),c.end(),greater<int>());
  LL ans=(q*n+n*(n-1)/2)*p;
  LL ruiseki=0;
  for(LL i=0;i<n;i++){
    ruiseki+=c[i];
    ans=max(ans,ruiseki+(q*(n-i-1)+(n-i-2)*(n-i-1))*p-(n*(n-1)/2)*p);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >


int main()
{
    int n,x,t;
    scanf("%d%d%d",&n,&x,&t);
    int ans=(n/x)*t;
    if(n%x) ans+=t;
    printf("%d",ans);
}


Measured memory_bytes: 3720
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int a = K;
        int b = K;
        int c = K;
      	int sum = 0;
      
        for (int A=1; A<=a; A++) {
			for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			}
        } 
        System.out.println(sum);
    }
  
private static int gcd(int m, int n) {
    while (n > 0)
    {
        int temp = n;
        n = m % n; // % is remainder
        m = temp;
    }
  	return m;
}
}



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

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

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    map<string, int>mp;
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        mp[S]++;
    }
    printf("AC x %d\n", mp["AC"]);
    printf("WA x %d\n", mp["WA"]);
    printf("TLE x %d\n", mp["TLE"]);
    printf("RE x %d\n", mp["RE"]);
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
int t[9],d;
bool used[11];
bool C(void){
  int r=(t[0]+t[1]+t[2])%t[9];
  return ((t[3]+t[4]+t[5])%t[9]==r&&(t[6]+t[7]+t[8])%t[9]==r&&(t[0]+t[3]+t[6])%t[9]==r&&(t[1]+t[4]+t[7])%t[9]==r&&(t[2]+t[5]+t[8])%t[9]==r&&(t[0]+t[4]+t[8])%t[9]==r&&(t[2]+t[4]+t[6])%t[9]==r);
}
 
int dfs(int d){
  if(d==10)return C()?1:0;
  if(t[d]!=0)return dfs(d+1);
  int res = 0;
  for(int i=1;i<=10;i++){
    if(!used[i]){
      t[d]=i;
      used[i]=1;
      res+=dfs(d+1);
      used[i]=0;
      t[d]=0;
    }
  }
  return res;
}
main(){
  while(1){
    memset(used,0,sizeof(used));
    for(int i=0;i<10;i++){
      cin>>t[i];
      if(t[i]>0)used[t[i]]=1;
    }
    if(t[0]==-1)break;
    cout<<dfs(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3040
#include<stdio.h>

int main(void)

{

int i,n;

int number;

long long int sum=0;

int min=0;

int max=0;


scanf("%d",&n);


for(i=0;i<n;i++)

{

scanf("%d",&number);


if(i==0)

{

min = number;

max = number;

}

if(number<min) min = number;

if(number>max) max = number;


sum += number;

}


printf("%d %d %lld\n",min,max,sum);


return 0;

}

Measured memory_bytes: 600
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N, K;
	cin >> N >> K;
	int A[2000];
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	ll ans = 0;
	sort(A, A+N);
	for(int i = 0; i < K; i++){
		ans += A[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
typedef long double ld ;
int main()
{
    ios;
    ld a, b , h ;
    cin >> a >> b >> h;
    cout <<( (a+b) * h )/ 2  << el ;
}































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

using namespace std;

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

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1.0);

ll n, k;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n >> k;
    if ((n - 1) * (n - 2) / 2 < k) cout << -1 << endl;
    else {
        ll cur = (n - 1) * (n - 2) / 2;
        cout << n + cur - k - 1 << endl;
        for (int i = 2; i <= n; ++i) {
            cout << 1 << ' ' << i << endl;
        }
        for (int u = 2; u <= n && cur > k; ++u) {
            for (int v = u + 1; v <= n && cur > k; ++v) {
                cout << u << ' ' << v << endl;
                --cur;
            }
        }
    }
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
    	try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			String target = "";
			for (int i = 0; i < n; i++) {
				target += sc.nextInt();
				if (i != n-1) target += " ";  //空白を入れる
			}
			String a = "";
			for (int i=1; i<n+1; i++) a += i;
			List<String> list = new ArrayList<String>();
			list = permutation(list,a,"");

			//結果出力---------------------------------------------------
			int index = -1;
			for (int i = 0; i < list.size(); i++) {
				if (list.get(i).equals(target)){
					index = i;
					break;
				}
			}
 			if (index != 0) System.out.println(list.get(index - 1));  //前の順列が存在したら出力する
 			System.out.println(list.get(index));  //与えられた数列を出力する
 			if (index != list.size()-1) System.out.println(list.get(index + 1));  //次の順列が存在したら出力する
    	}
  }

    static List<String> permutation( List<String> list,String input, String ans){
    	//1まで削ったらその回を終了して、答えをListに入れる
    	if (input.length() <= 1) {
    		list.add(ans + input);  //最後の数字はここでくっつく
    	} else {
    		for (int i=0; i<input.length(); i++) {  //inputの1、2、3…char目を分離して、残りの方に挿入する
    			permutation(list ,input.substring(0, i) + input.substring(i + 1), ans + input.charAt(i) + " "); //空白を入れる
    		}
    	}
    	return list;
    }
}


Measured memory_bytes: 176036
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

ll getMax(vll &a){
    ll res=-INF;
    for(auto x: a){
        res = max(res, x);
    }
    return res;
}

vll vecPlus(vll &a, vll &b){
    vll res(ALL(a));
    for(ll i=0; i< a.size(); i++){
        res[i] += b[i];
    }
    return res;
}

int main(){
    ll H, W, K;
    cin >> H>> W>> K;
    vector<string> S(H);
    REP(i, H) cin >> S[i];
    
    ll ans = H+W+1;
    REP(msk, 1LL<<(H-1)){
        vll rowCut(1, 0);
        REP(j, H-1){
            if(msk >> j & 1){
                rowCut.push_back(j+1);
            }
        }
        ll cntMsk = rowCut.size()-1;
        rowCut.push_back(H);
        bool failed=false;
        ll s = 0, t = 0;
        vll rowBlockWhite(rowCut.size()-1, 0);
        vll currWhite(rowCut.size()-1, 0);
        while(t<W){
            fill(ALL(rowBlockWhite), 0);
            while(t < W){
                fill(ALL(currWhite), 0);
                //* calculate current column
                REP(i, rowCut.size()-1){
                    ll cntWhite = 0;
                    //*  process [rowCut[i], rowCut[i+1])
                    for(ll ii = rowCut[i]; ii < rowCut[i+1]; ii++){
                        if(S[ii][t] == '1') currWhite[i]++;
                    }
                    if(currWhite[i] > K){ //* row cut is wrong
                        failed = true;
                        break;
                    }
                }
                if(failed) break;
                vll testWhite = vecPlus(rowBlockWhite, currWhite);
                bool includeThisColumn = true;
                REP(i, rowCut.size()-1){
                    if(testWhite[i] > K){
                        includeThisColumn = false;
                        break;
                    }
                }
                if(includeThisColumn){
                    rowBlockWhite = testWhite;
                    fill(ALL(currWhite), 0);
                    t++;
                } else{
                    s = t;
                    cntMsk++;
                    break;
                }

            }
            if(failed) break;
        }
        if(failed) continue;
        ans = min(ans, cntMsk);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, u, v = list(map(int, readline().split()))
    tmd = collections.defaultdict(list)
    for i in range(n-1):
        tma, tmb = list(map(int, readline().split()))
        tmd[tma-1] += [tmb-1]
        tmd[tmb-1] += [tma-1]

    qlt = [[0, u-1]]
    qlt = collections.deque(qlt)
    fqt = collections.defaultdict(int)
    fqt[u-1]
    while True:
        if len(qlt) != 0:
            cost, tmp = qlt.popleft()
            for tmv in tmd[tmp]:
                if tmv not in fqt:
                    qlt.append([cost + 1, tmv])
                    fqt[tmv] = cost + 1
        else:
            break

    qla = [[0, v-1]]
    qla = collections.deque(qla)
    fqa = collections.defaultdict(int)
    fqa[v-1]
    while True:
        if len(qla) != 0:
            cost, tmp = qla.popleft()
            for tmv in tmd[tmp]:
                if tmv not in fqa:
                    qla.append([cost + 1, tmv])
                    fqa[tmv] = cost + 1
        else:
            break
    mt = 0
    for kt, vt in sorted(fqt.items(), key=lambda x: x[1], reverse=True):
        if vt < fqa[kt]:
            mt = max(mt, fqa[kt])
    print(mt - 1)


if __name__ == '__main__':
    solve()


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

int main() {
    //input
    string str1,str2;
    cin >> str1 >> str2;
    reverse(str1.begin(),str1.end());
    if(str1 == str2){
        cout << "YES ";
    }else{
        cout << "NO";
    }

    return 0;
}

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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a*b)>(c*d))
        cout<<a*b;
    else if((a*b)<(c*d))
        cout<<c*d;
    else cout<<a*b;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <string>
#include <numeric>
#include <algorithm>

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

int n, m, count;
std::vector<std::pair<int,int>> data;
std::set<int> friends;

void f(int k) {
    if (count >= 2) return;

    for (auto d:data) {
        if(d.first == k) {
            int t = d.second;
            friends.insert(t);
            count++;
            f(t);
            count--;
        }else if(d.second == k && d.first != 1){
            int t=d.first;
            friends.insert(t);
            count++;
            f(t);
            count--;
        }
    }
}

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

    std::vector<int> result;

    for (;;) {
        std::cin >> n >> m;
        if (n == 0 && m == 0) break;
        data.resize(m);
        rep(i, m) std::cin >> data.at(i).first >> data.at(i).second;
        count = 0;

        f(1);

        result.push_back(friends.size());
        data.clear(); data.shrink_to_fit();
        friends.clear();
    }

    for (auto r : result) std::cout << r << "\n";
    return 0;
}

Measured memory_bytes: 3328
# Python3 program to Find Number of digits 
# in base b. 

import math 

# function to print number of 
# digits 
def findNumberOfDigits(n, base): 
	
	# Calculating log using base 
	# changing property and then 
	# taking it floor and then 
	# adding 1. 
	dig = (math.floor(math.log(n) /math.log(base)) + 1)
	return dig

# Driver method 

# taking inputs 
n,k=map(int,input().split())

# calling the method 
print(findNumberOfDigits(n, k))

# This code is contributed by 
# Manish Shaw (manishshaw1) 


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <string.h>

using namespace std;

int main(void){
	string a, b;

	cin >> a >> b;

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());


	reverse(b.begin(), b.end());


	if (a < b){
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;

	return 0;	
}

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

int main(){
	double a,b,c,d,e,f,x,y;
	while(cin >> a >> b >> c >> d >> e >> f){
		x = ((c*e-b*f)/(a*e-b*d))/1.0;
		y = ((a*f-c*d)/(a*e-b*d))/1.0;
		if(x == -0.0) x = 0.0;
		if(y == -0.0) y = 0.0;
		cout << fixed << setprecision(3);
		cout << x << " " << y << endl;
	}
}

Measured memory_bytes: 0
n = int(input())

a = []
for i in range(n):
    name, t = map(str, input().split())
    a.append([name, int(t)])

s = input()

cnt = 0
cnt_flag = 0
for i, j in a:
    if cnt_flag:
        cnt += j
    if s == i:
        cnt_flag = 1
print(cnt)


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    string s,t;
    i32 n,m,p,q,r;
    cin >> n >> s;
    vi csumR(n+1); rep(i,n) csumR[i+1] += csumR[i] + (s[i]=='R' ? 1 : 0);
    vi csumG(n+1); rep(i,n) csumG[i+1] += csumG[i] + (s[i]=='G' ? 1 : 0);
    vi csumB(n+1); rep(i,n) csumB[i+1] += csumB[i] + (s[i]=='B' ? 1 : 0);

//    debug => ok
//    for(auto i : csumR) cout << i << ' ';
//    cout << '\n';    for(auto i : csumG) cout << i << ' ';
//    cout << '\n';    for(auto i : csumB) cout << i << ' ';
//    cout << '\n';

    i64 cnt = 0;
    for(i32 i = 0; i < n-2; ++i) {
        for(i32 j = i+1; j < n-1; ++j) {
            if(s[i]==s[j]) continue;
//            cout << s[i] << ' ' << s[j] << '\n';  // debug

            char chh1 = min(s[i], s[j]);
            char chh2 = max(s[i], s[j]);
//            cout << chh1 << ' ' << chh2 << '\n';  // debug


            if(chh1 == 'G' && chh2 == 'R') {
                cnt += csumB[n] - csumB[j+1];
                if(j+j-i < n) cnt -= (s[j+j-i]=='B' ? 1 : 0);
            }
            else if(chh1 == 'B' && chh2 == 'G') {
                cnt += csumR[n] - csumR[j+1];
                if(j+j-i < n) cnt -= (s[j+j-i]=='R' ? 1 : 0);
            }
            else if(chh1 == 'B' && chh2 == 'R') {
                cnt += csumG[n] - csumG[j+1];
                if(j+j-i < n) cnt -= (s[j+j-i]=='G' ? 1 : 0);
            }
//            else cout << "!" << '\n';  // debug
//            debug(cnt);
        }
    }

    /**
     * WA * 4 .. large case
     */
    cout <<  cnt       << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

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

  if (n==1){
    cout << "Hello World" << endl;
  }else{
    cin >> a;
    cin >> b;
    cout << a+b << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, ll>;
vector<P> G[100100];

int main()
{
    ll N, M;
    cin >> N >> M;
    ll H[N];
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }

    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(P(b, H[b]));
        G[b].push_back(P(a, H[a]));
    }
    bool seen[N];
    fill_n(seen, N, false);
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (!seen[i])
        {
            bool is_count = true;
            for (P g : G[i])
            {
                int to;
                ll height;
                tie(to, height) = g;
                if (height < H[i])
                {
                    seen[to] = true;
                }
                else
                {
                    is_count = false;
                    break;
                }
            }
            if (is_count)
            {
                ans++;
            }
        }
    }

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

Measured memory_bytes: 12020
import java.util.*;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] result = new String[n];
        
        int c0 = 0;
        int c1 = 0;
        int c2 = 0;
        int c3 = 0;
        
        for(int i=0;i<n;i++){
            result[i] = sc.next();
            if(result[i].equals("AC")){
                c0++;
            }else if(result[i].equals("WA")){
                c1++;
            }else if(result[i].equals("TLE")){
                c2++;
            }else if(result[i].equals("RE")){
                c3++;
            }
        }
        System.out.println("AC x " + c0 );
        System.out.println("WA x " + c1 );
        System.out.println("TLE x " + c2 );
        System.out.println("RE x " + c3 );
    }
}


Measured memory_bytes: 63508
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    string s, t;
    cin >> s >> t;
    ll MAX = 0;
    rep(i, s.size() - t.size() + 1) {
        ll cnt = 0;
        for (ll j = 0; j < t.size(); j++) {
            if (s[i + j] == t[j]) cnt++;
        }
        chmax(MAX, cnt);
    }

    cout << t.size() - MAX << "\n";
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int j,n,m,po,no,flag,cnt=0,cnt2,ans,ar[100000],x,y,i,co[100000],sum=0;
    string str[1000],ptr,sr,tr,rtr,rt;
    vector<long long int>v(100000,0);
    set<string>s;
    queue<long long int>qu;
    set<string>::iterator it;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
            sum=sum+i;
    }

cout<<sum<<endl;


}



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

void fin(int a){
    string ans = "Draw";
    if(a > 0) ans = "Alice";
    if(a < 0) ans = "Bob";
    cout << ans << endl;
}

int main() {
    int t1, t2, r1, r2;
    cin >> t1 >> t2 >> r1 >> r2;
    fin(r1 >= 0 && r2 >= 0 ? r1-r2 : t2-t1);
    return 0;
}


Measured memory_bytes: 3212
#include<cstdio>
#include<cstring>
long long s,s2; int k,l,v[110]; char c[110];
int main() {
	scanf("%s%d",c+1,&k); l=strlen(c+1);
	for (int i=2; i<=l; ++i)
		if (c[i]!=c[1]) { v[0]=1; break; }
	if (!v[0]) return printf("%lld\n",(1ll*l*k>>1)),0; 
	memset(v,1,sizeof v);
	for (int i=2; i<=l; ++i)
		c[i]==c[i-1]&&v[i-1]&&(++s,v[i]=0);
	s*=k; c[1]==c[l]&&v[l]&&(s+=k-1);
	memset(v,1,sizeof v);
	for (int i=l-1; i; --i)
		c[i]==c[i+1]&&v[i+1]&&(++s2,v[i]=0);
	s2*=k; c[1]==c[l]&&v[1]&&(s2+=k-1);
	s2<s&&(s=s2); printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 888
#!/usr/bin/env python3
s_x, s_y, t_x, t_y = map(int, input().split())
ans = ""
ans += "R" * (t_x - s_x) + "U" * (t_y - s_y)
ans += "L" * (t_x - s_x) + "D" * (t_y - s_y)
ans += "D" + "R" * (t_x - s_x + 1) + "U" * (t_y - s_y + 1) + "L"
ans += "U" + "L" * (t_x - s_x + 1) + "D" * (t_y - s_y + 1) + "R"
print(ans)


Measured memory_bytes: 3060
use std::collections::HashSet;

fn read_number() -> Result<usize, String> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim()
        .parse::<usize>()
        .map_err(|err| format!("Error at read_number(): {}", err.to_string()))
}

fn read_number_each_line(n: usize) -> Result<Vec<i32>, String> {
    (0..n)
        .map(|_| read_number().map(|x| x as i32))
        .collect::<Result<Vec<_>, _>>()
}

fn read_line() -> Result<Vec<String>, String> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.split_whitespace()
        .map(|x| {
            x.parse::<String>()
                .map_err(|err| format!("Error at read_line(): {}", err.to_string()))
        })
        .collect::<Result<Vec<_>, _>>()
}

fn dictionary() -> Result<(), String> {
    let mut set = HashSet::new();

    let n = read_number()?;
    let lines = (0..n)
        .map(|_| read_line())
        .collect::<Result<Vec<Vec<String>>, String>>()?;

    for line in lines {
        let elem = line[1].to_string();
        match line[0].as_str() {
            "insert" => {
                set.insert(elem);
            }
            "find" => {
                let yn = if set.contains(&elem) { "yes" } else { "no" }.to_owned();
                println!("{}", yn);
            }
            _ => (),
        };
    }

    Ok(())
}

fn main() {
    dictionary();
}



Measured memory_bytes: 105392
import heapq
n,t = map(int,input().split())
a_list = list(map(int,input().split()))
low = a_list[0]
sa = []
for i in range(1,n):
  if a_list[i]>=a_list[i - 1]:
    sa.append(a_list[i] - low)
  elif a_list[i]<= low:
    low = a_list[i]
print(sa.count(max(sa)))

  
  

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

using namespace std;

int main()
{
	int n; cin >> n;
	vector<int> h(n), dp(n);
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; ++i) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
			        dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

ll h,w,n;
vi dx{-1, 0, 1};
vi dy{-1, 0, 1};
map<P, bool> used;
map<P, bool> black;

int check(P z){
  int res = 0;
  rep(i, 3){
    rep(j, 3){
      P zahyo = mp(z.fi+dy[i], z.se+dx[j]);
      if(black[zahyo]) res++;
    }
  }
  return res;
}

int main(){
  cin >> h >> w >> n;
  int a,b;
  ll ans[10];
  rep(i,10) ans[i] = 0;
  rep(i,n){
    cin >> a >> b;
    black[mp(a-1,b-1)] = true;
  }
  for(auto it = black.begin(); it != black.end(); it++){
    P z = mp(it->fi.fi, it->fi.se);
    if(black[z]){
      rep(i, 3){
        rep(j, 3){
          int x,y;
          y = z.fi+dy[i]; x = z.se+dx[j];
          if(0 < y && y < h-1 && 0 < x && x < w-1 && !used[mp(y,x)]){
            ans[check(mp(y,x))]++;
          }
          used[mp(y,x)] = true;
        }
      }
    }
  }

  ans[0] = (w-2) * (h-2);
  rrep(i,9) ans[0] -= ans[i];
  rep(i,10) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 212736
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

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

  int a = 0;
  for (int i = 0; i + 1 < N; ++i){
    if (S[i + 1] != S[i]) a++;
  }
  cout << N - 1 - max(a - 2 * K, 0) << endl;
}


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


int main() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  rep(i, N) cin >> P[i];
  rep(i, N) cin >> Q[i];

  vector<int> a(N);
  rep(i, N) a[i] = i + 1;

  map<vector<int>, int> mp;
  do {
    mp[a] = mp.size();
  } while (next_permutation(a.begin(), a.end()));

  int ans = abs(mp[P] - mp[Q]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5248
n = int(input())
a = list(map(int,input().split()))

if n == 2:
    print(max(a))
else:
    l = [0 for i in range(n)]
    r = [0 for i in range(n)]
    
    def gcd(x,y):
        while y != 0:
            x, y = y, x%y
    #        print(x,y)
        return(x)
    
    for i in range(1,n):
        l[i] = gcd(l[i-1],a[i-1])
        r[n-i-1] = gcd(r[n-i],a[n-i])
  #  print(l)
  #  print(r)
    ans = 0
    for i in range(n):
        if l[i] == -1:
            ans = max(ans,r[i])
        elif r[i] == -1:
            ans = max(ans,l[i])
        else:
            ans = max(ans,gcd(l[i],r[i]))
    print(ans)

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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
const int N = 200010;
int a[N];
ll BIT[N];

void update(int x,ll val)
{
      for(; x <= N; x += x&-x)
        BIT[x] = max(BIT[x],val);
}

ll query(int x)
{
     ll Res = 0;
     for(; x > 0; x -= x&-x)
        Res = max(BIT[x],Res);
     return Res;
}


int main()
{

    SPEED;
    int n;
    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];
    }
    ll Cur,x,Ans=0;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> x;
        Cur = query(a[i]);
        update(a[i],x+Cur);
        Ans = max(Ans,query(a[i]));
    }
    cout << Ans << endl;
    R 0;
}


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

namespace ABC162B
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());

            long sum = 0;
            for(int i = 1; i <= n; i++)
            {
                if(i%3==0 || i%5 == 0)
                {
                    continue;
                }

                sum += i;
            }

            Console.WriteLine($"{sum}");
        }
    }
}


Measured memory_bytes: 27220
from collections import deque
from sys import stdin
input = stdin.readline

N = int(input())
neighborlist = [None for _ in range(N+1)]
for _ in range(1, N+1):
    node, _, *L = list(map(int, input().split()))
    neighborlist[node] = L

distancelist = [-1]*(N+1)
queue = deque()
queue.append(1)
distancelist[1] = 0
while queue:
    node = queue.popleft()
    distance = distancelist[node]
    for neighbor in neighborlist[node]:
        if distancelist[neighbor] == -1:
            distancelist[neighbor] = distance + 1
            queue.append(neighbor)

for i in range(1, N+1):
    print(i, distancelist[i])


Measured memory_bytes: 6032
#include <stdio.h>
#include <string.h>

#define N 2000000
int array[N];
int num;

void swap(int* a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void swap_array(int n) {
  if (n == 0) return;
  int parent = (n-1) / 2;
  if (array[n] > array[parent]) {
    swap(&array[n], &array[parent]);
    swap_array(parent);
  }
}

void shift_down(int i) {
  int child = 2*i + 1;
  if (child >= num) return; 
  if (array[child] < array[child + 1]) {
    child++;
  }
  if (array[i] < array[child]) {
    swap(&array[i], &array[child]);
    shift_down(child);
  }
}

void push(int x) {
  array[num] = x;
  num++;
  swap_array(num-1);
}

int pop() {
  int t = array[0];
  array[0] = array[--num];
  shift_down(0);
  return t;
}

int main() {
  char s[80];
  int x;
  while (scanf("%s", &s)) {
    if (strcmp(s, "end") == 0) break;
    if (s[0] == 'e')    printf("%d\n", pop());
    else{
      scanf("%d", &x);
      push(x);
    }
  }

  return 0;
}



Measured memory_bytes: 5636
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize ("Ofast,unroll-loops,-ffloat-store,no-stack-protector")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

string to_string(const string& s) { return '"' + s + '"'; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cout << "#" << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif
 
#define cin_exception cin.exceptions(cin.failbit);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using ld = long double;  using ui = uint_fast32_t;
using ll = int_fast64_t; using ul = uint_fast64_t;

// -----------------------------------------------------------------------------

void solve() {
    int r; cin >> r;
    ld MATH_PI = 6.28318530717958623200;
    cout << MATH_PI * r << '\n';
}

// -----------------------------------------------------------------------------

int main() {
    fast_io; cout_precision;
#ifdef LOCAL
    cin_exception;
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }
}

Measured memory_bytes: 3844
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
Max = 0

#先頭
for i in range(N):
    if V[i] <= C[i]:
        continue
    X,Y = V[i],C[i]
    tmpMax = X - Y
    for j in range(i+1,N):
        if V[j] <= C[j]:
            continue
        if Max < (X + V[j]) - (Y + C[j]):
            X = X + V[j]
            Y = Y + C[j]
            tmpMax = X - Y
    if Max < tmpMax:
        Max = tmpMax
        
print(Max)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
    int N;
    int i,j,k;
    int counter = 0;
    scanf("%d",&N);

    int L[N];
    
    for(i=0;i<N;i++){
        scanf("%d", &L[i]);
    }
    for(i=0;i<N;i++){
        for(j=i+1;j<N;j++){
            if(L[j] == L[i]){
                continue;
            }
            for(k=j+1;k<N;k++){
                if(L[k] == L[i] || L[k] == L[j]){
                    continue;
                }
                if(L[i]+L[j] > L[k] && L[j]+L[k] > L[i] && L[k]+L[i] > L[j]){
                    counter++;
                }
            }
        }
    }

    printf("%d",counter);

    return 0;
}

Measured memory_bytes: 1712