akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 500005, M = 1000000007;

int ast(int x, int n)
{
    int ans = 1;
    while (n)
    {
        if (n % 2 == 1)
            ans = (ans * 1LL * x) % M;
        x = (x * 1LL * x) % M;
        n /= 2;
    }
    return ans;
}

int f[N], rf[N];
void pre()
{
    f[0] = 1;
    for (int i = 1; i < N; ++i)
        f[i] = (f[i - 1] * 1LL * i) % M;
    rf[N - 1] = ast(f[N - 1], M - 2);
    for (int i = N - 2; i >= 0; --i)
        rf[i] = (rf[i + 1] * 1LL * (i + 1)) % M;
}

int C(int n, int k)
{
    return ((f[n] * 1LL * rf[k]) % M * 1LL * rf[n - k]) % M;
}

void solv()
{
    int n, m;
    scanf("%d%d", &n, &m);
    int ans = 0;
    for (int q = 0; q <= n; ++q)
    {
        int u = 1;
        u = (u * 1LL * C(n, q)) % M;
        u = (u * 1LL * C(m, q)) % M;
        u = (u * 1LL * f[q]) % M;
        u = (u * 1LL * C(m - q, n - q)) % M;
        u = (u * 1LL * f[n - q]) % M;
        u = (u * 1LL * C(m - q, n - q)) % M;
        u = (u * 1LL * f[n - q]) % M;
        if (q % 2 == 0)
        {
            ans = (ans + u) % M;
        }
        else
        {
            ans = (ans - u + M) % M;
        }
    }
    printf("%d\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    pre();
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 7744
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

int main(void){
	ll n,i,a[123456],sum=0ll,d;
	bool flag = true;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
		sum += a[i];
	}
	if( sum % ((n*(n+1))/2) ){
		cout << "NO" << endl;
		return 0;
	}
	d = sum / ((n*(n+1))/2); sum = 0ll;
	a[n] = a[0];
	for(i=0; i<n; ++i){
		if((a[i] - a[i+1] + d) < 0 || (a[i] - a[i+1] + d) % n){
			cout << "NO" << endl;
			return 0;
		}else{
			sum += ((a[i] - a[i+1] + d) / n);
		}
	}
	if(flag && sum == d){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		FasterScanner sc = new FasterScanner(System.in);

		double r = sc.nextInt();
		System.out.println(2*r*Math.PI);
		
		sc.close();
	}
	
	class FasterScanner {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FasterScanner() {
			this(System.in);
		}

		public FasterScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void close() {
			try {
				mIs.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}


Measured memory_bytes: 33180
def solve():
    H, W = map(int, input().split())
    field = [list(input()) for i in range(H)]

    dp = [[0] * W for i in range(H)]
    for h in range(1,H):
        if field[h-1][0] == '.' and field[h][0] == '#':
            dp[h][0] = dp[h-1][0] + 1
        else:
            dp[h][0] = dp[h-1][0]

    for w in range(1,W):
        if field[0][w-1] == '.' and field[0][w] == '#':
            dp[0][w] = dp[0][w-1] + 1
        else:
            dp[0][w] = dp[0][w-1]
    
    for w in range(1,W):
        for h in range(1,H):
            fromUpward = dp[h-1][w]
            if field[h-1][w] == '.' and field[h][w] == '#':
                fromUpward += 1

            fromLeft = dp[h][w-1]
            if field[h][w-1] == '.' and field[h][w] == '#':
                fromLeft += 1
            
            dp[h][w] = min(fromUpward, fromLeft)
    
    ans = dp[H-1][W-1]
    if field[0][0] == '#':
        ans += 1

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
const int MX_N = 100005;
int n,m;
vector<vector<int>> tree(MX_N,vector<int>());

struct DP{
    ll dp;
    DP(ll dp=1):dp(dp){}
    DP operator + (const DP& r) const {
        return DP((dp*r.dp)%m);
    }
    DP addroot() const{
        return DP((dp+1)%m);
    }
};

vector<DP> dp[MX_N];
DP ans[MX_N];


DP dfs1(int v,int p=-1){
    DP dpsum;
    dp[v] = vector<DP>(tree[v].size());
    rep(i,tree[v].size()){
        int c = tree[v][i];
        if(c == p) continue;
        dp[v][i] = dfs1(c,v);
        dpsum = dpsum + dp[v][i];
    }
    return dpsum.addroot();
}

void dfs2(int v,int p=-1,DP dpP = DP()){
    int deg = tree[v].size();
    rep(i,deg) if(tree[v][i] == p) dp[v][i] = dpP;

    vector<DP> dpL(deg+1);
    rep(i,deg) dpL[i+1] = dpL[i] + dp[v][i];

    vector<DP> dpR(deg+1);
    for(int i=deg-1;i>=0;--i) dpR[i] = dpR[i+1] + dp[v][i];

    ans[v] = dpL[deg];

    rep(i,deg){
        int c = tree[v][i];
        if(c == p) continue;
        DP dpV = dpL[i] + dpR[i+1];
        dfs2(c,v,dpV.addroot());
    }
}

int main(){
    cin >> n >> m;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs1(0);
    dfs2(0);
    rep(i,n) cout << ans[i].dp << endl;
    return 0;
}

Measured memory_bytes: 24320
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
const int inf = 1001001001;
typedef long long ll;

int main(){
    int n, m, x; cin >> n >> m >> x;
    int c[n], a[n][m];
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
        }
    }
    int min_cost = inf;
    rep(i, 1<<n){
        int cost = 0;
        int algorithm[12] = {};
        rep(j, n){
            if(i>>j & 1){
                cost += c[j];
                rep(k, m) algorithm[k] += a[j][k];
            }
        }
        bool ok = true;
        rep(j, m){
            if(algorithm[j] < x) ok = false;
        }
        if(ok) min_cost = min(min_cost, cost);
    }
    if(min_cost == inf) cout << "-1" << endl;
    else cout << min_cost << endl;
}

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

int main() {
    string s;
    int k;
    cin >> s >> k;
    float n = s.size();

    set<string> subs;
    for (int i = 1; i <= 5; i++) {
        rep(j, n - i + 1) {
            string sub = s.substr(j, i);
            subs.insert(sub);
        }
    }

    int i = 1;
    for (auto sub : subs) {
        if (i == k) {
            cout << sub << endl;
            break;
        }
        i++;
    }

    return 0;
}


Measured memory_bytes: 1664
object Main {
  case class Line(string: String) {
    def strings: Seq[String] = string.split(' ')
    def ints: Seq[Int] = strings.map(_.toInt)
    def i(n: Int): Int = ints(n)
  }

  def readLine: Line = Line(io.StdIn.readLine())
  def readLines(n: Int): Seq[Line] = List.fill(n)(Line(io.StdIn.readLine()))

  def yesNo(b: Boolean): String = if (b) "Yes" else "No"

  def main(args: Array[String]) {
    println(scala.math.pow(readLine.i(0), 3).toInt)
  }
}

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

int main() {
	
	ll x, y;
	cin >> x >> y;
	ll i = x;
	int ans = 0;
	while(i <= y){
		i *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int matrix[200][200] = { { 0 } };

int main(){
	while(true){
		int N;
		cin >> N;
		if(N == 0){ break; }
		for(int i = 0; i < 200; ++i){
			for(int j = 0; j < 200; ++j){ matrix[i][j] = 1000; }
		}
		map<string, int> names;
		while(N--){
			string line;
			cin >> line;
			int delimiter = line.find_first_of('-');
			string a = line.substr(0, delimiter), b = line.substr(delimiter + 1);
			if(names.find(a) == names.end()){
				names.insert(make_pair(a, static_cast<int>(names.size())));
			}
			if(names.find(b) == names.end()){
				names.insert(make_pair(b, static_cast<int>(names.size())));
			}
			int ai = names[a], bi = names[b];
			matrix[ai][bi] = 1;
		}
		cout << names.size() << endl;
		for(int k = 0; k < names.size(); ++k){
			for(int i = 0; i < names.size(); ++i){
				for(int j = 0; j < names.size(); ++j){
					if(matrix[i][j] > matrix[i][k] + matrix[k][j]){
						matrix[i][j] = matrix[i][k] + matrix[k][j];
					}
				}
			}
		}
		for(int i = 0; i < names.size(); ++i){
			for(int j = 0; j < names.size(); ++j){
				if(matrix[i][j] <= 2 || matrix[j][i] <= 2){ continue; }
				for(int k = 0; k < names.size(); ++k){
					if(matrix[i][k] == 1 && matrix[j][k] == 1){
						matrix[i][j] = matrix[j][i] = 0;
						break;
					}
					if(matrix[k][i] == 1 && matrix[k][j] == 1){
						matrix[i][j] = matrix[j][i] = 0;
						break;
					}
				}
			}
		}
		for(int k = 0; k < names.size(); ++k){
			for(int i = 0; i < names.size(); ++i){
				for(int j = 0; j < names.size(); ++j){
					if(matrix[i][j] > matrix[i][k] + matrix[k][j]){
						matrix[i][j] = matrix[i][k] + matrix[k][j];
					}
				}
			}
		}
		int M;
		cin >> M;
		while(M--){
			string line;
			cin >> line;
			int delimiter = line.find_first_of('-');
			string a = line.substr(0, delimiter), b = line.substr(delimiter + 1);
			if(names.find(a) == names.end() || names.find(b) == names.end()){
				cout << "NO" << endl;
				continue;
			}
			int ai = names[a], bi = names[b];
			if(matrix[ai][bi] < 1000){
				cout << (matrix[ai][bi] % 2 == 1 ? "YES" : "NO") << endl;
				continue;
			}
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }




int main(){

    long long S;
    scanf("%lld",&S);
    long long W;
    scanf("%lld",&W);
    
    if(S<=W){
        cout << "unsafe" << endl;
    }

    else{
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3764
import sys

def main():
    input = sys.stdin.readline
    a, b = map(str, input().split())
    c = int(a+b)

    d = int(c**0.5)
    if d**2 == c:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct A {
    bool operator<(const A& a) const {
        return y < a.y;
    }
    int p, y, i;
};

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

    vector<vector<A>> a(n, vector<A>());
    for (int j = 0; j < m; j++) {
        int p, y;
        cin >> p >> y;
        p--;
        a[p].push_back({ p, y, j });
    }

    vector<A> r(m);
    for (int i = 0; i < n; i++) {
        sort(a[i].begin(), a[i].end());
        int k = 0;
        for (auto& o : a[i]) {
            o.y = k++;
            r[o.i] = o;
        }
    }

    for (int j = 0; j < m; j++) {
        printf("%06d%06d\n", r[j].p + 1, r[j].y + 1);
    }

    return 0;
}

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

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int32_t main(){
	boost;

	vector<string> a;

	int n , l;

	cin >> n >> l;

	string temp;
	for(int i = 0 ; i < n ; ++i){
		cin >> temp;
		a.push_back(temp);
	}

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

	for(auto i : a)
		cout << i;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.isEmpty()) {
                break;
            }
            String[] values = line.split(",");
            int[] numbers = new int[5];
            int[] counts = new int[13];
            for (int i = 0; i < 5; i++) {
                int number = Integer.parseInt(values[i]);
                numbers[i] = number;
                counts[number - 1] += 1;
            }
            String result = null;
            Arrays.sort(counts);
            if (counts[12] == 4) {
                result = "four card";
            } else if (counts[12] == 3 && counts[11] == 2) {
                result = "full house";
            } else {
                Arrays.sort(numbers);
                if (numbers[4] - numbers[0] == 4
                        || (numbers[0] == 1 && numbers[1] + numbers[4] == 23)) {
                    result = "straight";
                } else if (counts[12] == 3) {
                    result = "three card";
                } else if (counts[11] == 2) {
                    result = "two pair";
                } else if (counts[12] == 2) {
                    result = "one pair";
                }
            }

            out.println(result);
        }
    }
}

Measured memory_bytes: 9340
#include <iostream>
#include <cmath>

using namespace std;
const int maxn = 1e6 + 111;
int N, K, a[maxn];

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


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

int main(){
  int n;
  cin >> n;
  while(n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a.at(i);

    vector<int> s(n+1);
    s.at(0) = 0;
    for(int i=1;i<n+1;i++) s.at(i) = s.at(i-1)+a.at(i-1);

    int ans=a.at(0);
    for(int i=1;i<n+1;i++){
      for(int j=0;j<i;j++){
        ans = max(s.at(i)-s.at(j),ans);
      }
    }

    cout << ans << endl;

    cin >> n;
  }
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

void solve() 
{   
    ll k,a,b;cin>>k>>a>>b;
    if(b<=a||k<=a){
        cout<<k+1<<endl;
    }else{
        ll kk=k-(a-1);
        ll abs=b-a;
        ll ans=a+abs*(kk/2);
        if(kk%2)ans++;
        ans=max(ans,k+1);
        cout<<ans<<endl;
    }
}

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


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

int main() {

  int input1,input2;
  char c;

  int cnt = 0;
  int num = 0;
  int a = 0;

  while( cin >> input1 >> c >> input2 ) {

    cnt += input1*input2;
    num += input2;
    a++;

  }

  int out = num/a;
  if ( (num%a) >= (a+1)/2 ) out++;

  cout << cnt << endl << out << endl;

  return 0;

}

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

using namespace std;

int n;
vector<pair<int, int>> vs[15];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int x, y;
      cin >> x >> y;
      --x;
      vs[i].push_back(make_pair(x, y));
    }
  }
  
  int mx = 0;
  for (int s = 0; s < (1 << n); ++s) {
    bool ok = true;
    for (int i = 0; i < n; ++i) {
      if (!(s & (1 << i))) continue;
      for (auto p : vs[i]) {
        int x = p.first;
        int y = p.second;
        int c = (s >> x) & 1;
        if (c != y) {
          ok = false;
        }
      }
    }
    if (ok) {
      mx = max(mx, __builtin_popcount(s));
    }
  }
  cout << mx << endl;
}

Measured memory_bytes: 256
a = list(map(int,input().split()))
b = [0, 0, 0, 0]

b[0] = a[0]*a[2]
b[1] = a[0]*a[3]
b[2] = a[1]*a[2]
b[3] = a[1]*a[3]

b.sort()

print(b[3])

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

vll binary_convert(ll n){
    vll s;
    ll size = 0;

    while(n / (ll)(pow(2,size)) > 0)size++;
    rep(i,size + 1){
        s.pb(n / (ll)(pow(2,i)));
        n %= (ll)(pow(2,i));
    }

    return s;
}

ll fib(ll n){
    vll a(n+1);
    a[0] = 1;
    a[1]  = 1;

    REP(i,2,n+1){
        a[i] = a[i-1] + a[i-2];
        a[i] %= mod;
    }

    return a[n-1];
}

int main()
{
    string s;
    cin >> s;
    REP(i,1,SIZE(s)){
        if(s[i] == s[i-1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)          
{
	int H = 10, W = 10;
	int i, j;

	while (H != 0 && W != 0)
	{
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0) break;
		for (i = 0; i < H; i++)
		{
			for (j = 0; j < W; j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

signed main(void){
  
  int N; cin >> N;
  string S; cin >> S;
  int Q; cin >> Q;
  
  vector<set<int>> se(26);
  
  for(int i = 0; i < N; i++){ 
    char c = S[i];
    se[(int)(c-'a')].insert(i);
  }
  
  while(Q--){
    
    int which; cin >> which;
    if(which == 1 ){ 
      //変更クエリ
      int pos; char new_one; cin >> pos >> new_one; pos--;
      char old_one = S[pos];
      se[(int)(old_one-'a')].erase(pos);
      se[(int)(new_one-'a')].insert(pos);
      
      S[pos] = new_one;
     
    }
    else{
      //計算クエリ
      int l,r; cin >> l >> r; l--; 
      int cnt = 0;
      
       for(int i = 0; i < 26; i++){ //それぞれの文字が範囲内に含まれているのかを計算
         
         auto check = se[i].lower_bound(l); //l以上で最初の値
         if( check == se[i].end() ){ continue;}
        
         if( r <= *check){ continue;}
         
         cnt++;
       }//for-i
      
      cout << cnt << endl;
        
    }//else
  }//which
  
  return 0;
} 
  

Measured memory_bytes: 24196
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

    int N, M;
    cin >> N >> M;
    vector<long> A(N);
    priority_queue<long> que;
    rep(i, N) {
        cin >> A[i];
        que.push(A[i]);
    }

    long n_max;
    for (int i = 0; i < M; i++) {
        n_max = que.top() / 2;
        que.pop();
        que.push(n_max);
    }

    long sum = 0;
    while(!que.empty()) {
        sum += que.top();
        que.pop();
    } 

    cout << sum << "\n";
}

Measured memory_bytes: 2168
//organize , stay in moment and work -- Abhinav IIIT-A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ar array
#define f(i,x,n) for(int i=x;i<n;++i)
#define sz(s) s.size()
#define pb push_back
void solve(){
    int a[3];
    f(i,0,3)
    cin>>a[i];
    sort(a,a+3);
    if((a[0]==a[1] || a[1] == a[2] )&& a[0]!=a[2] )
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
void tp(){
    int n; cin>>n;
    bool tp=1;
    while(n--){
        int cp;
        cin>>cp;
        if(cp%2==0){
            if(!(cp%3==0 || cp%5==0))
                tp=0;
        }
    }
    tp ? cout<<"APPROVED" : cout<<"DENIED";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;t=1;
    //cin>>t;
    while(t--)
    tp();
    return 0;
}


Measured memory_bytes: 256
class cmbs(object):
    def __init__(self, mod):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 6 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

    def cmbl(self, n, r):
        t = 1
        r = min(r, n-r)
        for i in range(n - r + 1, n + 1):
            t = t * i % self.mod
        return t * self.g2[r] % self.mod
def main():
    N = int(input())
    mod = 10**9 + 7
    C = list(map(int, input().split()))
    C.sort()
    r = 0
    for i, v in enumerate(C[:-1]):
        t = pow(2, N-i-2, mod) * (N- i + 1)
        t *= v * pow(2, i, mod)
        r += t
    r += C[-1] * pow(2, N-1, mod)
    r *= pow(2, N, mod)
    r %= mod
    return r
print(main())


Measured memory_bytes: 88908
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define MOD 1000000007
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
using namespace std;
typedef vector<int> vi;
typedef list<int> li;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename P> P dectobin(P a){if(a==0)return 0; else return(a%2 + 10*dectobin(a/2));}
template<typename Y> Y bintodec(Y a){int ans=0,b=1,t=a; while (t){int ld=t%10; t/=10;ans+=ld* b;b=b*2;} return ans; }
template<typename H> H modExp(H x, H n){ int r=1; while(n>0){if(n%2==1){r=(r*x)%MOD;}x=(x*x)%MOD;n/=2;}return r;}
template<typename T> T isPowerOfTwo(T x){return x && (!(x & (x - 1)));}	
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
//template<typename T> T extendedEuclid(T A,T B){if(B==0){d=A; x=1;y=0;}else{ extendedEuclid(B,A%B);int temp=x; x=y; y=temp-(A
//B)*y;}}
int32_t main(){
	boost;osit;
	int n,l,p=0,sum=0;
	cin>>n>>l;
	int arr[n];
	vi v,w;
	rep(i,0,n){
		arr[i]=l+i;
		sum+=arr[i];
		if(arr[i]==0) {p=1;}
		else if(arr[i]>0) v.pb(arr[i]);
		else w.pb(arr[i]);
	} 
	if(p==1) {cout<<sum;}
	else{
		if(v.size()==0){
			cout<<sum-w[w.size()-1];
		}
		else if(w.size()==0){
			cout<<sum-v[0];
		}
	}
	return 0;
}

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

 using namespace std;
 
 #define ll long long
 #define inf ((unsigned) ~0)
 #define odd(x) x&1
 #define pow2(x) 1 << x
 #define log2bin(x) 32-__builtin_clz(x)-1
 #define popcnt(x) __builtin_popcount(x)
 #define mod7(x) x%1000000007

 #define cinarr(A,len) for(int i=0;i<len;i++){cin>>A[i];}
 #define coutarr(A,len) for(int i=0;i<len;i++){cout<<A[i]<<' ';}cout<<endl
 #define coutin(V) for(auto& i : V){cout << i << ' ';}cout<<endl // for vect and set
 #define coutmap(U) for(auto& i : U){cout << i.first << "->" << i.second << ' ';}cout<<endl // for map

 // ==== fast function ====
 /*
 bool prime(long long n){ const long long sqrtn = floor(sqrt(n)); if(n!=2 && n&1^1){return false;} for(long long i = sqrtn; i>=3; i-=2){ if(n%i==0){ return false;} } return true;}
 long long fastexp(long long base, long long pwr){ if(!pwr || !base)return 0; if(n&1^1){return fastexp(a*a, b/2);}else{return a*fastexp(a*a, b/2);}}
 */
 
/*========================================================================*/
/* strategi/note:



/================================*/



void solve(){
    int n;
    cin >> n;
    
    int h[n];
    cinarr(h,n);
    
    int dp[n]; // max cost to reach n+1 stone
    dp[0] = 0; // max cost to reach 1st stone is 0 because it is the initial pos
    dp[1] = abs( h[1]-h[0] );
    
    for(int i = 2; i<n; i++){ // from third index
        dp[i] = min( dp[i-2]+abs(h[i-2]-h[i]) ,  dp[i-1]+abs(h[i-1]-h[i]) );
    }
    
    cout << dp[n-1] << endl;

}

int main(){
     ios_base::sync_with_stdio(0);
     cin.tie(0);
     //cout.setprecision( ) // iomanip **

	solve();
//	int t;cin>>t;while(t--){solve();}
//	int t;cin>>t;((int))* ans=new ((int))[(( ))];solve();((int)) in;while(t--){cin>>in;cout<<ans[in-(( )) ];}delete[] ans;

	 //cout.flush(); cin.get();
     return 0;
}


Measured memory_bytes: 4304
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(int i = p;i < q;i++)
#define ll long long

ll CONS = 1e9 + 7;

using namespace std;

int main(void) {
	ll k;
	cin >> k;
	if (k == 0)cout << 2 << endl << 0 << " " << 0 << endl;
	else if (k == 1) cout << 2 << endl << 0 << " " << 2 << endl;
	else if (k <= 50) {
		cout << k << endl;
		cout << 1;
		rep(i, 2, k + 1) {
			cout << " " << i;
		}
		cout << endl;
	}
	else {
		vector<ll> num = vector<ll>(50);
		ll loop = k / 50;
		rep(i, 0, 50)num[i] = i + loop;
		ll last = k % 50;
		rep(i, 0, 50) {
			if (i < last) {
				num[i] += 50 - last + 1;
			}
			else {
				num[i] -= last;
			}
		}
		cout << 50 << endl;
		cout << num[0];
		rep(i, 1, 50) {
			cout << " " << num[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	int sum=0,round=0;
	for(int i=100;i>=1;--i){
		if(a%i==0&&b%i==0){
			round++;
		}
		if(round==k){
			cout<<i;
			
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

typedef long long int llint;

int main()
{
    llint n;
    scanf("%lld",&n);
    llint a=sqrt(n);
    for(llint i=a;;i--)
    {
        if(n%i==0)
        {
            printf("%lld\n",i+n/i-2);
            return 0;
        }
    }
}

Measured memory_bytes: 256
n = int(input())
H = list(map(int,input().split()))
dp = [0 for _ in range(n+1)]
dp[1] = abs(H[1] - H[0])
for i in range(2,n):
    b1 = dp[i-1] + abs(H[i] - H[i-1])
    b2 = dp[i-2] + abs(H[i] - H[i-2])
    dp[i] = min(b1,b2)
print(dp[-2])

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

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

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1000000 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

void work()
{
    int n, m;
    cin >>n >>m;
    if(n > m) swap(n, m);
    for(int i = 0; i < m; i++) cout <<n;
    cout <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


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

using namespace std;

int main() {

    int N;
    cin >> N;
    int hi[N], dystruct[N];
    for(int i = 0 ; i < N; i++) {

        cin >> hi[i];
    }

    dystruct[0] = 0;
    dystruct[1] = dystruct[0] + abs(hi[1] - hi[0]);
    for(int i = 2 ; i < N; i++) {

        dystruct[i] = min(dystruct[i - 1] + abs(hi[i] - hi[i - 1]), dystruct[i - 2] + abs(hi[i] - hi[i - 2]));
    }

    cout << dystruct[N - 1];

    return 0;
}

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

using namespace std;
int main()
{

long long int N,K,d,z;
cin >> N >> K;
int arr[N]={0};
while(K--)
{
    cin>> d ;

    for(int i=0;i<d;i++)
    {

        cin >> z;
        arr[z-1]++;
    }

}
int p=0;
for(int i=0;i<N;i++)
{
    if(arr[i]==0) p++;

}

cout<<p;


return 0;
}


Measured memory_bytes: 3600
<?php

fgets(STDIN);
$input = explode(" ", trim(fgets(STDIN)));

$l = count($input);

$a = 0;
$b = 0;

for ($i = 0; $i < $l; ++$i) {
    $m = max($input);
    $index = array_search($m, $input);

    $input[$index] = -1;

    if (($i % 2) == 0) {
        $a += $m;
    } else {
        $b += $m;
    }
}

echo $a - $b;


Measured memory_bytes: 5112
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const int maxn = 1e6 + 3;
bool pal(string s) {
	for(int i = 0; i < s.size(); i++) if(s[i] != s[s.size()-1-i]) return false;
	return true;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	long double x;
	cin >> x;
	x/=3;
	cout << fixed << setprecision(15) << x*x*x << '\n';
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N;
  cin>>  N;
  vector<LL> A(N + 1);
  
  REP(i,N+1){
    cin >> A[i];
  }
  
  vector<LL> B(N + 1, 0);

  B[N] = A[N];
  
  REP(i,N){
    LL j = N - i -1;
    B[j] = A[j] + B[j + 1];
  }

  LL sum = 0;
  LL ha = 0;
  LL totyuu = 1;

  REP(i,N+1){
    totyuu -= A[i];
    ha += A[i];

    sum += A[i];
    sum += totyuu;
    
    if(totyuu<0){
      cout << -1 << endl;
      return 0;
    }

    if (i != N)
    {
      totyuu *= 2;
      totyuu = min(B[i + 1], totyuu);
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 4784
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin>>N;
  vector<double> v(N);
  rep(i,N) cin>>v[i];

  SORT(v);
  double  ans = (v[0] + v[1]) / 2.0;
  for(int i = 2; i < N; i++){
    ans = (ans + v[i]) / 2.0;
  }
  cout<<ans<<endl;
}


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

const int N = 1e5+10;

typedef long long ll;

ll a[N],b[N];
int n;
ll sum1,sum2;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",a+i);
	for(int i=1;i<=n;i++) scanf("%lld",b+i);
	for(int i=1;i<=n;i++) {
		if(a[i] > b[i]) sum1 += (a[i] - b[i]);
		if(a[i] < b[i]) sum2 += (b[i] - a[i])/2;
	}
	if(sum1 <= sum2) puts("Yes");
	else puts("No");
}

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

int main() {
  
  int x,a,b;
  cin >> x >> a >> b;
  
  if ( a >= b ){
    cout << "delicious" << endl;
  }else if ( b - a <= x ){
    cout << "safe" << endl;
  }else if ( b - a > x ){
    cout << "dangerous" << endl;
  } 
  
}



Measured memory_bytes: 256
def judge_status_summary():
    # 入力
    N = int(input())
    S = [input() for _ in range(N)]
    # 判別処理 
    # リスト初期化
    result_list = ['AC', 'WA', 'TLE', 'RE']
    count_list = [0, 0, 0, 0]
    # 集計
    for i in range(N):
        one_count_up_inxex = result_list.index(S[i])
        count_list[one_count_up_inxex] += 1
    # 表示
    for i in range(4):
        print(result_list[i], 'x', count_list[i])

judge_status_summary()

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a,b,c,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("snuke"),alphh("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),s;

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


    bool fl=true;
       cin >> h >> w;
       rep(i,h){
           rep(j,w){
               cin >> s;
               rep(k,s.size()){
                   if(s[k]!=alph[k]){
                       fl=false;
                   }
               }
               if(fl){
                   cout << alphh[j] << i+1 << endl;
                   return 0;
               }
               fl=true;
           }
       }
return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int[][] adj = { { 2 }, { 2, 5 }, { 0, 1, 3, 6 }, { 2, 7 }, { 5 },
				{ 1, 4, 6, 9 }, { 2, 5, 7, 10 }, { 3, 6, 8, 11 }, { 7 },
				{ 5, 10 }, { 6, 9, 11, 12 }, { 7, 10 }, { 10 } };
		String g = "0ABCDEFGHIJK0";
		Map<String, Integer> m = new HashMap<String, Integer>();
		Deque<String> deque = new ArrayDeque<String>();
		int step = 1;
		deque.offer(g);
		m.put(g, 0);
		while (!deque.isEmpty() && step < 11) {
			int size = deque.size();
			for (int k = 0; k < size; k++) {
				String s = deque.pop();
				char[] c = s.toCharArray();
				for (int i = 0; i < 13; i++) {
					if (c[i] == '0') {
						for (int j = 0; j < adj[i].length; j++) {
							c[i] = c[adj[i][j]];
							c[adj[i][j]] = '0';
							String n = String.valueOf(c);
							if (!m.containsKey(n)) {
								m.put(n, step);
								deque.offer(n);
							}
							c[adj[i][j]] = c[i];
							c[i] = '0';
						}
					}
				}
			}
			step++;
		}
		while (true) {
			int p = scanner.nextInt();
			if (p == -1)
				break;
			char[] cc = new char[13];
			cc[0] = p == 0 ? '0' : (char) (p - 1 + 'A');
			for (int i = 1; i < 13; i++) {
				p = scanner.nextInt();
				cc[i] = p == 0 ? '0' : (char) (p - 1 + 'A');
			}
			String st = String.valueOf(cc);
			Set<String> set = new HashSet<String>();
			set.add(st);
			deque.clear();
			deque.offer(st);
			step = 0;
			boolean flag = false;
			String ans = "";
			loop: while (!deque.isEmpty() && step < 11) {
				int size = deque.size();
				for (int w = 0; w < size; w++) {
					String s = deque.pop();
					if (m.containsKey(s)) {
						flag = true;
						ans = s;
						break loop;
					}
					char[] cs = s.toCharArray();
					for (int i = 0; i < 13; i++) {
						if (cs[i] == '0') {
							for (int j = 0; j < adj[i].length; j++) {
								cs[i] = cs[adj[i][j]];
								cs[adj[i][j]] = '0';
								String news = String.valueOf(cs);
								if (!set.contains(news)) {
									set.add(news);
									deque.offer(news);
								}
								cs[adj[i][j]] = cs[i];
								cs[i] = '0';
							}
						}
					}

				}
				step++;
			}
			System.out.println(flag ? m.get(ans) + step : "NA");

		}
	}
}

Measured memory_bytes: 103832
using System;
using System.Collections.Generic;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = Console.ReadLine().Split(' ');
           
            int a1 = int.Parse(A[0]);
            int a2 = int.Parse(A[1]);
            int a3 = int.Parse(A[2]);
            
            
            var a = new List<int>();
            a.Add(a1);
            a.Add(a2);
            a.Add(a3);
           
            a.Sort();
           
            Console.WriteLine("{0} {1} {2}", a[0],a[1],a[2]);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 9400
N = int(input())
A = list(map(int, input().split()))
A.sort()
B = [0] * (10**6+1)
ans = 0
for a in A:
    if B[a] == 0:
        ans += 1
        B[a] = 2
        tmp = 2*a
        while tmp <= 10**6:
            B[tmp] = 1
            tmp += a
    elif B[a] == 2:
        B[a] = 1
        ans -= 1
print(ans)

Measured memory_bytes: 32232
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  static final int INF = Integer.MAX_VALUE / 2;
  static int n;
  static long ww;
  static int[] w, v;

  static final boolean DEBUG = false;

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

    n = sc.nextInt();
    ww = sc.nextInt();
    w = new int[n];
    v = new int[n];
    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      v[i] = sc.nextInt();
    }

    int[][][] dp = new int[n + 1][n + 1][3 * n + 1];
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
        Arrays.fill(dp[i][j], -INF);
      }
    }

    dp[0][0][0] = 0;
    for(int i = 1; i <= n; i++){
      for(int j = 0; j <= n; j++){
        for(int k = 0; k <= 3 * n; k++){
          if(j - 1 >= 0 && j <= i && k - (w[i - 1] - w[0]) >= 0){
            if(DEBUG){
              System.out.println("in");
            }
            dp[i][j][k] = Math.max(
                dp[i - 1][j - 1][k - (w[i - 1] - w[0])] + v[i - 1], dp[i - 1][j][k]);
          }
          else{
            dp[i][j][k] = dp[i - 1][j][k];
          }
          if(DEBUG){
            System.out.println("dp[" + i + "][" + j + "][" + k + "] = " + dp[i][j][k]);
          }
        }
      }
    }

    int max = 0;
    for(int i = 1; i <= n; i++){
      for(int j = 0; j <= 3 * n; j++){
        if((long)w[0] * (long)i + j <= ww){
          max = Math.max(max, dp[n][i][j]);
        }
      }
    }

    System.out.println(max);
  }
}


Measured memory_bytes: 35388
a = 0
while True:
    H, W = map(int, input(). split())
    if H == 0 and W == 0:
        break
    for j in range(1, H+1):
        for i in range(1, W+1):
            if j==1 or j==H or i==1 or i==W:
                print("#", end='')
            else:
                print(".", end='')
        print()
    print()    
    a += 1


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

const int N = 300;
const int mo = 1e9 + 7;

int fac[2*N + 5], inv[2*N + 5];

int fpm(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1) {
      res = 1ll * res * x % mo;
    }
    x = 1ll * x * x % mo;
    y >>= 1;
  }
  return res;
}

void init() {
  fac[0] = 1;
  for (int i = 1; i <= 2*N; ++i) fac[i] = 1ll * fac[i-1] * i % mo;
}

int n, x;
int a[2*N + 5], b[2*N + 5];
int f[2*N + 5][2*N + 5][2*N + 5];

int main() {

  init();
  scanf("%d", &n);

  memset(b, -1, sizeof b);
  for (int i = 0; i < 2*n; ++i) scanf("%d", a + i), b[a[i]] = i;
  for (int i = 0; i < 2*n; i += 2) x += (a[i] == -1) && (a[i + 1] == -1); 

  f[1][0][0] = 1;

  for (int i = 1; i <= 2*n; ++i) {
    for (int j = 0; j <= 2*n; ++j) {
      for (int k = 0; k <= 2*n; ++k) if (f[i][j][k]) {
        if (b[i] == -1) {
          f[i + 1][j + 1][k] = (f[i + 1][j + 1][k] + f[i][j][k]) % mo;
          f[i + 1][j][k + 1] = (f[i + 1][j][k + 1] + f[i][j][k]) % mo;
          if (k) f[i + 1][j][k - 1] = (f[i + 1][j][k - 1] + f[i][j][k]) % mo;
        } else if (a[b[i] ^ 1] == -1) {
          f[i + 1][j][k + 1] = (f[i + 1][j][k + 1] + f[i][j][k]) % mo;
          if (j) f[i + 1][j - 1][k] = (f[i + 1][j - 1][k] + 1ll * f[i][j][k] * j) % mo;
        } else {
          f[i + 1][j][k] = f[i][j][k];
        }
      }
    }
  }

  int ans = 1ll * fac[x] * f[2*n+1][0][0] % mo;
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 855040
def examA():
    K, X = LI()
    if K*500>=X:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
    return

def examB():
    N = I()
    S = SI()
    ans = 0
    for i in range(N-2):
        if S[i:i+3]=="ABC":
            ans +=1
    print(ans)
    return

def examC():
    N = I()
    P = LI()
    Q = LI()
    Cp = [i for i in itertools.permutations(P,N)]; Cp.sort()
    Cq = [i for i in itertools.permutations(Q, N)]; Cq.sort()
#    print(Cp)
#    print(Cq)
    for k,i in enumerate(Cp):
        flag = True
        for j in range(N):
            if P[j]!=i[j]:
                flag = False
                break
        if flag:
            a = k
            break
    for k,i in enumerate(Cq):
        flag = True
        for j in range(N):
            if Q[j]!=i[j]:
                flag = False
                break
        if flag:
            b = k
            break
    ans = abs(a-b)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()


Measured memory_bytes: 50160