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

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[200001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

typedef struct {
	data obj[400001];
	int size;
} min_heap;

void push(data x, min_heap* h)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key < h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(min_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key < h->obj[j].key) j ^= 1;
		if (h->obj[j].key < h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

int main()
{
	int i, j, t, T, N, K[200001], L[200001], R[200001], tmp, flag[200001];
	long long ans;
	data d, c[200001];
	min_heap h;
	scanf("%d", &T);
	for (t = 1; t <= T; t++) {
		scanf("%d", &N);
		ans = 0;
		for (i = 1; i <= N; i++) {
			scanf("%d %d %d", &(K[i]), &(L[i]), &(R[i]));
			c[i-1].key = K[i];
			c[i-1].id = i;
			flag[i] = 0;
		}
		merge_sort(c, N);
		
		h.size = 0;
		for (i = 1, j = 0; i <= N; i++) {
			for (; j < N && c[j].key == i; j++) {
				if (L[c[j].id] > R[c[j].id]) {
					d.key = L[c[j].id] - R[c[j].id];
					d.id = c[j].id;
					push(d, &h);
				}
			}
			while (h.size > i) pop(&h);
		}
		while (h.size > 0) {
			d = pop(&h);
			flag[d.id] = 1;
			ans += L[d.id];
		}
		
		for (i = N, j = N - 1; i >= 1; i--) {
			for (; j >= 0 && c[j].key == i; j--) {
				if (R[c[j].id] > L[c[j].id]) {
					d.key = R[c[j].id] - L[c[j].id];
					d.id = c[j].id;
					push(d, &h);
				}
			}
			while (h.size > N - i) pop(&h);
		}
		while (h.size > 0) {
			d = pop(&h);
			flag[d.id] = 1;
			ans += R[d.id];
		}
		
		for (i = 1; i <= N; i++) if (flag[i] == 0) ans += (L[i] < R[i])? L[i]: R[i];
		printf("%lld\n", ans);
	}

	fflush(stdout);
	return 0;
}

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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	int n, x; cin >> n >> x;
	int m[105];
	int sum = 0;
	rep(i, 0, n){
		cin >> m[i];
		sum += m[i];
	}
	int ans = n;
	x -= sum;
	sort(m, m+n);
	ans += x/m[0];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef long long  ll;
typedef unsigned long long  ull;
typedef long double ld;
#define lp(i,n)      for(int i=0;i<n;i++)
#define lpi(i,j,n)   for(int i=j;i<n;i++)
#define lpd(i,j,n)   for(int i=j;i>=n;i--)
#define MP           make_pair
#define clr(v, d)    (memset(v, d, sizeof(v)))
#define all(v)     (v.begin()),(v.end())
#define N 100005
const double pi = acos(-1);

ll n,t,m,k;

ll ans;
ll mod = 1e9 +7;
ll mat[105][105],a[10005];



int main() {
 
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("e.txt","r",stdin); 
// freopen("e_out.txt","w",stdout); 
cout.precision(10);



cin>>n>>k;
vector<int>a(n),cnt;
map<int,int>mp;
lp(i,n){
  cin>>a[i];
  mp[a[i]]++;
}
for(auto& u:mp)cnt.push_back(u.second);
sort(all(cnt));
lp(i,(int)cnt.size()-k)ans+=cnt[i];
cout<<ans;



  
}
  
 



// bool isPrime(ll h){
//      for(ll i=0;primes[i]*primes[i]<= h;i++)
//      if (h%primes[i]==0)
//      	return 0;
//      return h!=1;
//  }
 bool isPrime(ll g){
   if((g%2==0 && g>2) || g==1)return 0;
   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;
   return 1;   
 
 }

Measured memory_bytes: 14336
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
dist_int = 0

for i in range(n-1):
    for j in range(i+1, n):
        square = 0
        for k in range(d):
            square += (x[i][k]-x[j][k])**2
        if (square**0.5).is_integer():
            dist_int += 1

print(dist_int)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
	char c;
	cin >> c;
	char cc;
	switch (c)
	{
	case'A':
		cc = 'T';
		break;

	case'T':
		cc = 'A';
		break;

	case'C':
		cc = 'G';
		break;

	case'G':
		cc = 'C';
		break;
	default:
		break;
	}
	cout << cc << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val (A, B, Q) = readLine()!!.split(" ").map {it.toInt()}
    val s = TreeSet<Long>(Array(A) { readLine()!!.toLong() }.toList())
    val t = TreeSet<Long>(Array(B) { readLine()!!.toLong() }.toList())
    val x = Array(Q) { readLine()!!.toLong() }

    val INF = 1e15.toLong()

    for (a in x) {
        val sl = s.floor(a) ?: -INF
        val su = s.ceiling(a) ?: INF
        val tl = t.floor(a) ?: -INF
        val tu = t.ceiling(a) ?: INF

        var res = a - Math.min(sl, tl)
        res = Math.min(res, Math.max(su, tu) - a)
        res = Math.min(res, tu - sl + Math.min(tu - a, a - sl))
        res = Math.min(res, su - tl + Math.min(su - a, a - tl))

        println(res)
    }
}


Measured memory_bytes: 81716
/* 
 * Project: AtCoder Beginners Contest 170 B - Crane and Turtle
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/14
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

int x;
int y;

void solve() {

    if (x == 100 || y == 1) {
        printf("No\n");
        return;
    } 
    
    for (int i=0;i<=x;i++) {
        int foot = i*2+(x-i)*4;
        if (foot == y) {
            printf("Yes\n");
            return;
        }
    }
    printf("No\n");
    return;
}

int main() {

    scanf("%d", &x);
    scanf("%d", &y);

    solve();

}

Measured memory_bytes: 3164
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;



map<string, int> mp;

signed main() {
	ios::sync_with_stdio(false);
	int n, k, i, j;
	cin >> n >> k;
	vector<int> b(n, 0);
	rep(i, n) {
		int a;
		cin >> a;
		a--;
		b[a]++;
	}
	sort(ALL(b));
	int type = b.size();
	if (type < k) {
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	for (int i = 0; i < type - k; i++) {
		ans += b[i];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    double l = Integer.parseInt(in.readLine());
    System.out.println(Math.pow(l/3,3));
  }
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n - 1 + m), b(n - 1 + m);
    vector<int> c(n, 0);
    vector<vector<int>> edges(n);
    for(int i = 0; i < n - 1 + m; ++i){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
        edges[a[i]].push_back(b[i]);
        ++c[b[i]];
    }
    queue<int> que;
    for(int i = 0; i < n; ++i){
        if(!c[i])
            que.push(i);
    }

    vector<int> v(n, 0);

    while(!que.empty()){
        int t = que.front();
        que.pop();

        for(auto& x : edges[t]){
            if(--c[x] == 0){
                v[x] = t + 1;
                que.push(x);
            }
        }
    }
    for(auto& x : v)
        cout << x << endl;
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	cin>>s;
	map<char,int> mp;
	mp['A'] = 1;mp['C'] = 1;mp['G'] = 1;mp['T'] = 1;
	int ans = -1000;
	for(int i=0;i<=s.size();i++)
	{
		for(int j=0;j<s.size();j++)
		{
			string now = s.substr(j,i);
			bool isok = true;
			for(int k=0;k<now.size();k++)
			{
				if(mp[now[k]] == 0)
				{
					isok = false;
				}
			}
			if(isok)
			{
				int m = now.size();
				ans = max(ans,m);
			}
		}
	}
	if(ans)
	cout<<ans<<endl;
	else
	cout<<0<<endl;
}

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

int main(){
  ll N;
  cin >> N;
  ll ans=0;
  for(ll i=1;i<=N;i++){
    for(ll j=1;j*i<=N;j++){
        ans+=j*i;
    }
  }
  cout << ans <<endl;
}

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

using namespace std;

int main(){
  int x[5];
  for(int i = 0; i < 5; i++){
    int x;
    cin >> x;
    if(x == 0){
      cout << i + 1 << endl;
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3524
k=int(input())
ans=[0]*(k+1)
ans[0] = 7
if 7 % k == 0:
  print(1)
  quit()
for i in range(1,k):
  ans[i] += ((10*ans[i-1]+7)%k)
  if ans[i] % k == 0:
    print(i+1)
    break
else:
  print(-1)

Measured memory_bytes: 71516
# coding: utf-8
# Your code here!
n,W = [int(i) for i in input().split()]
wv = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行

dp = [0]*(W+1)
dp[0]=0
newdp = [0]*(W+1)
for i in range(n):
    w, v = wv[i]
    for j in range(W+1):
        newdp[j] = dp[j]
    for j in range(W+1):
        if j+w <= W:
            if newdp[j+w] < dp[j] + v:
                newdp[j+w] = dp[j] + v
    newdp, dp = dp, newdp
#    print(dp)

print(max(dp))    
    
#print(dp)

Measured memory_bytes: 43116
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n, x, y, z;
string s[10000];

int main() {
	cin >> n;
	inc(i, n) { cin >> s[i]; }
	
	int ans = 0;
	inc(i, n) {
		inc(j, SI(s[i]) - 2) { if(s[i].substr(j, 2) == "AB") { ans++; } }
		if(s[i].front() != 'B' && s[i].back() == 'A') { x++; }
		if(s[i].front() == 'B' && s[i].back() != 'A') { y++; }
		if(s[i].front() == 'B' && s[i].back() == 'A') { z++; }
	}
	
	if(z == 0) {
		ans += min(x,y);
	} else {
		ans += z - 1;
		if(x > 0) { ans++; x--; }
		if(y > 0) { ans++; y--; }
		ans += min(x, y);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <string>

#define MAX 4000

using namespace std;

int dp[MAX + 2][MAX + 2];

int main(void){

  string s,t;
  while(getline(cin, s)){
    getline(cin, t);

    fill(dp[0], dp[MAX + 1] + MAX + 2, 0);

    for(int i = 0 ; i < s.size() ; i++){
      for(int j = 0 ; j < t.size() ; j++){
	if(s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
	else dp[i + 1][j + 1] = 0;
      }
    }
    int ans = 0;
    for(int i = 0 ; i <= s.size() + 1 ; i++){
      for(int j = 0 ; j <= t.size() + 1 ; j++){
	ans = max(dp[i][j], ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 63760
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int n; cin >> n;

	cout << (180 + (n - 3) * 180) << endl;

	return 0;
}

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

int main() {
  int N;
  scanf("%d",&N);
  int num[4];
  for (int i=0; i<4; i++) {
    num[i]=N%10;
    N/=10;
  }
  bool f=false;
  if (num[0]==num[1] && num[1]==num[2] && num[2]==num[3]) {
    f=true;
  } else if (num[0]==num[1] && num[1]==num[2] && num[2]!=num[3]) {
    f=true;
  } else if (num[0]!=num[1] && num[1]==num[2] && num[2]==num[3]) {
    f=true;
  }
  if (f) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


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

using namespace std;

const int mod = 1'000'000'007;

long long mpow(long long a, long long b);

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

	vector<int> b = a;
	int pri[1000010] = {};
	for (int i = 0; i < n; i++) {
		for (int j = 2; j * j <= a[i]; j++) {
			if (b[i] % j == 0) {
				int tmp = 0;
				while (b[i] % j == 0) {
					tmp++;
					b[i] /= j;
				}
				pri[j] = max(pri[j], tmp);
			}
		}
		if (b[i] != 1) {
			pri[b[i]] = max(pri[b[i]], 1);
		}
	}

	long long l = 1;
	for (int i = 2; i < 1000000; i++) {
		if (pri[i] != 0) {
			l *= mpow(i, pri[i]);
			l %= mod;
		}
	}

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += l * mpow(a[i], mod - 2);
		ans %= mod;
	}
	cout << ans << endl;

	return 0;
}

long long mpow(long long a, long long b)
{
	long long ans = 1;
	while (b != 0) {
		if ((b & 1) == 1) {
			ans *= a;
			ans %= mod;
		}
		a *= a;
		a %= mod;
		b >>= 1;
	}

	return ans;
}

Measured memory_bytes: 7588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int n;
	cin >> n;
	long double ans = pi * 2 * n ;
	cout << setprecision(10) << ans << '\n';
}


Measured memory_bytes: 3800
package main

import (
	"fmt"
)

func main(){
	var N int
	fmt.Scan(&N)
	H := make([]int,N)
	for i := 0; i < N; i++ {
		fmt.Scan(&H[i])
	} 
	count := 0
	for i := 0; i < N; i++ {
		flag := true
		for j := 0; j < i; j++ {
			if H[j] > H[i] {
				flag = false
			}
		}
		if flag {
			count = count + 1
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 512
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll w, h, x, y; cin >> w >> h >> x >> y;
    cout.precision(17);
    cout << fixed << (double) w * h / 2 << endl;
    if ((x == (double) w / 2) && (y == (double) h / 2)) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3756
n,k = map(int,raw_input().split(" "))

ans = 0

if k == 0:
  print n*n
  exit(0)

for b in range(k+1,n+1):
  # for a in range(k,n+1,b):
    # 0,1,...,  k,     k+1, k+2...,   b-1
    # b,b+1,... b+k, b+k+1, ...   ,   b+b-1
    # ........     , n
    buf = b-k
    buf2 = n/b
    buf = buf * buf2
    #print buf
    buf3 = buf2*b
    #print buf3
    if (n - buf3 - k + 1) > 0:
      buf += (n - buf3 - k + 1)
    ans += buf
    #print b,buf
    # and if 
print ans


Measured memory_bytes: 5764
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 200000;

vector<pair<pair<int,int>,int> >edges;
int L;

void add_edge(int a,int b,int c){
	edges.push_back(make_pair(make_pair(a,b),c));
}

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);

	for (int i=2;i<=19;i++){
		add_edge(i,i+1,0);
		add_edge(i,i+1,1<<(19-i));
	}

	cin>>L;
	int start=0;
	if (L>=(1<<18)*3){
		add_edge(1,2,start);
		L-=(1<<18);
		start+=(1<<18);
	}
	if (L>=(1<<18)*2)
	{
			add_edge(1,2,start);
			L-=(1<<18);
			start+=(1<<18);
	}
	for (int i=18;i>=0;--i){
		if (L>=(1<<i)){
			add_edge(1,(20-i),start);
			start+=(1<<i);
			L-=(1<<i);
		}
	}

	cout<<20<<" "<<edges.size()<<endl;

	for (int i=0;i<edges.size();i++){
		cout<<edges[i].first.first<<" "<<edges[i].first.second<<" "<<edges[i].second<<endl;
	}

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


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( 1e9 + 7 )


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

	int num0 = 0;
	for ( int i = 0; i < S.size(); i++ )
	{
		if ( S[i] == '0' )
		{
			num0++;
		}
	}

	int num1 = S.size() - num0;

	cout << min( num0, num1 ) * 2 << endl;

	return ( 0 );
}


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

int pop(void);
void push(int);
int top=0,A[100];

int main()
{
  int x,y,z;
  char In[100];

  
  while(scanf("%s",In)!=EOF)
    {
      if(In[0]=='+')
	{
	  x=pop();
	  y=pop();
	  push(x+y);
	}

      else if(In[0]=='-')
	{
	  x=pop();
	  y=pop();
	  push(y-x);
	}

      else if(In[0]=='*')
	{
	  x=pop();
	  y=pop();
	  push(x*y);
	}
      else push(atoi(In));
    }
  
  printf("%d\n",A[1]);

  return 0;
}

int pop(void)
{
  top--;
  return A[top+1];
}

void push(int a)
{
  top++;
  A[top]=a;
}
 

Measured memory_bytes: 548
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define name(x) #x
using namespace std;


const int INF = INT_MAX;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int N;
double dp[310][310][310];

double solve(int A, int B, int C){
    // 3個の皿がA枚, ...
    double val = dp[A][B][C];
    
    if(val > 0) return val;
    
    if (A == 0 && B == 0 && C == 0) return val =0;
    
    double add = 1.0*N/(A+B+C); //寿司の乗った皿にヒットするまでの回数の期待値。
    
    val = 0;
    
    if (A) val += (solve(A-1,B+1,C)+add)* A/(A+B+C);
    if (B) val += (solve(A,B-1,C+1)+add)* B/(A+B+C);
    if (C) val += (solve(A,B,C-1)+add)* C/(A+B+C);
    dp[A][B][C] = val;
    return val;
    
}

int main() {
    cin >> N;
    int max1 = 0, max2=0, max3=0;
    int a;
    
    for(auto i = 0; i<N; i++){
        cin >> a;
        max1 += (a ==1);
        max2 += (a ==2);
        max3 += (a ==3);
    }

    printf("%.12lf",solve(max3,max2,max1));
    
    
    return 0;
}




Measured memory_bytes: 225536
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
char c[300];
int main(){
    int n;
    cin >> n;
    string s;
    int L,R;
    cout << "? ";
    for(int i=1;i<=n;i++){
        cout << i << " ";
    }
    cout << endl;
    cin >> s;
    int ok = n+1;
    int ng = 1;
    while(ok-ng>1){
        int mid = (ok+ng)/2;
        cout << "? ";
        for(int j=0;j<n;j++){
            cout << mid+j << " ";
        }
        cout << endl;
        string t;
        cin >> t; 
        if(t==s){
            ng = mid;
        }else{
            ok = mid;
        }
    }
    //cerr << ok << endl;
    //cerr << L << " " << R << endl;
    L = ok;
    R = ok+n-2;
    for(int i=1;i<=2*n;i++){
        if(!(L<=i&&i<=R)){
            cout << "? ";
            cout << i << " ";
            for(int j=L;j<=R;j++){
                cout << j << " ";
            }
            cout << endl;
            cin >> s;
            if(s=="Red"){
                c[i] = 'R';
            }else{
                c[i] = 'B';
            }
        }else{
            cout << "? ";
            cout << i << " ";
            for(int j=1;j<L-1;j++){
                cout << j << " ";
            }
            for(int j=R+2;j<=2*n;j++){
                cout << j << " ";
            }
            cout << endl;
            cin >> s;
            if(s=="Red"){
                c[i] = 'R';
            }else{
                c[i] = 'B';
            }
        }
    }
    cout << "! ";
    for(int i=1;i<=2*n;i++){
        cout << c[i];
    }
    cout << endl;
    return 0;
}

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



int main()
{
    long long int i,j,n,o,m;
    char a[10];

    while(scanf("%lld %c %lld",&n,&a[0],&m)!=EOF)
    {


    if(a[0]=='+'){printf("%lld\n",n+m);}
    else if(a[0]=='-'){printf("%lld\n",n-m);}

    }
    return 0;
}


Measured memory_bytes: 128
M = 256
EPS = 1e-10
def calc_entropy(n, arr, input)
  out = input.zip(arr).map{ |l, r| (l + r) % M }
  cnt = [0] * 256
  out.each{ |i| cnt[i] += 1 }
  cnt.map{ |i| (i / n.to_f) * (Math.log(i / n.to_f)) if i != 0 }.compact.reduce(:+) * (-1)
end

def solve(n, input)
  min = 1 << 29
  ret = []
  (0..15).each do |s|
    (0..15).each do |a|
      (0..15).each do |c|
        arr = (1..n).each_with_object([s]){ |_, arr| arr << (a * arr[-1] + c) % M }[1..-1]
        ent = calc_entropy(n, arr, input)
        if ent < min && min - ent > EPS
          ret = [s, a, c]
          min = ent
        end
      end
    end
  end
  ret
end

loop do
  n = gets.to_i
  break if n == 0
  input = gets.split.map(&:to_i)
  puts solve(n, input) * ' '
end

Measured memory_bytes: 13996
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N, K; cin >> N >> K;
	vector<pair<ll, ll>> num(N);
	for (int i = 0; i < N; i++) {
		cin >> num[i].first >> num[i].second;
	}

	ll ans = 0;
	for (int i = -1; i < 32; i++) {
		if ((i != -1) && !(K & (1 << i)))continue;
		ll temp = 0;
		for (int j = 0; j < N; j++) {
			for (int k = i; k < 32; k++) {
				if (k == i) if (num[j].first & (1 << k))break;
				if ((!(K & (1 << k))) && (num[j].first & (1 << k))) {
					break;
				}
				else if (k == 31) {
					temp += num[j].second;
					//printf("i=%d j=%d\n", i, j);
				}
			}
		}
		ans = max(ans, temp);
	}

	cout << ans << endl;
}


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

int main ()
{
    int N ;
    cin >>N ;
    bool d= false;
    for(int i =1 ; i <=9 ; i++){
    for(int j = 1; j <=9 ; j++)
    {
        if(i*j==N)
           {

           d=true;
            break; }
    }}
    if(d)
        cout << "Yes";
    else
        cout << "No";



    return 0 ;
}


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

struct bellford
{
    const ll INF=LONG_LONG_MAX;
    struct edge {int u, v; ll w;};
    int nv, ne;
    vector<ll> d;
    vector<int> p;
    vector<edge> E;

    bellford(int nv, int ne) : nv(nv), ne(ne)
    {
        d.resize(nv, INF);
        p.resize(nv,-1);
    }

    void relax(int u, int v, ll w)
    {
        if(d[u]!=INF && d[v]>d[u]+w)
        {
            d[v]=d[u]+w;
            p[v]=u;
        }
    }

    bool get(int s)
    {
        d[s]=0; 
        for(int i=0; i<nv-1; i++)
            for(auto &e : E)
                relax(e.u, e.v, e.w);

        vector<bool> path(nv, false);
        path[nv-1]=true;
        int v=p[nv-1];
        while(v!=-1 && !path[v])
        {
            path[v]=true;
            v=p[v];
        }
        if(v!=-1) return false;
        return true;
    }
};


int main()
{
    int N, M;
    scanf("%d%d", &N, &M);
    bellford g(N, M);
    for(int i=0; i<M; i++)
    {
        int a, b;
        ll c;
        scanf("%d%d%lld", &a, &b, &c);
        g.E.push_back({a-1, b-1, -c});
    }
    if(g.get(0)) printf("%lld\n", -g.d[N-1]);
    else printf("inf\n");
    return 0;
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    
    ll n,p=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
     {cin>>a[i];p^=a[i];}
     if(p)
      cout<<"No";
      else cout<<"Yes";
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int INF=1e9;

int main(){
	string s;
	cin>>s;
	int N=(int)s.length();
	int diff=0;
	rep(i,N){
		if(s[i]=='g')diff++;
		else diff--;
	}
	cout<<diff/2;
}

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

int main(){
    int N,M;
    cin>>N>>M;

    vector<bool> all_loved(M);
    for(int i=0;i<M;i++){
        all_loved[i]=true;
    }

    int K;
    int a;
    for(int i=0;i<N;i++){
        cin>>K;
        vector<bool> loved(M);
        for(int j=0;j<K;j++){
            cin>>a;
            loved[a-1]=true;
        }
        for(int i=0;i<M;i++){
            if(!loved[i]){
                all_loved[i]=false;
            }
        }
    }

    int ans=0;
    for(int i=0;i<M;i++){
        if(all_loved[i]){
            ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, A: int, B: int):
    return N//(A+B) * A + min(N % (A+B), A)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(f'{solve(N, A, B)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75184
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int bt[40][2];
long long A;
long long K;
int main(){
  int Lj4PdHRW, i, j, k;
  long long cur, res, tmp;
  rd(N);
  rd(K);
  for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
    rd(A);
    for(i=0;i<40;i++){
      if(A&1LL<<i){
        bt[i][1]++;
      }
      else{
        bt[i][0]++;
      }
    }
  }
  res = cur = 0;
  for(i=39;i>=0;i--){
    if(K & 1LL<<i){
      tmp = cur;
      tmp += ((long long)bt[i][1]) << i;
      for(j=i-1;j>=0;j--){
        tmp += ((long long)max_L(bt[j][0], bt[j][1])) << j;
      }
      chmax(res, tmp);
      cur += ((long long)bt[i][0]) << i;
    }
    else{
      cur += ((long long)bt[i][1]) << i;
    }
  }
  chmax(res, cur);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int N, bt[40][2];
// ll A, K;
// {
//   int i, j, k;
//   ll res, cur, tmp;
// 
//   rd(N,K);
//   rep(N){
//     rd(A);
//     rep(i,40) bt[i][ if[A&1LL<<i,1,0] ]++;
//   }
// 
//   res = cur = 0;
//   for(i=39;i>=0;i--){
//     if(K & 1LL<<i){
//       tmp = cur;
//       tmp += ((ll)bt[i][1]) << i;
//       for(j=i-1;j>=0;j--) tmp += ((ll)max(bt[j][0],bt[j][1])) << j;
//       res >?= tmp;
// 
//       cur += ((ll)bt[i][0]) << i;
//     } else {
//       cur += ((ll)bt[i][1]) << i;
//     }
//   }
//   res >?= cur;
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D;
  cin >>D;
  
  if (D == 25)
    cout << "Christmas" << endl;
  
  if (D == 24)
    cout << "Christmas Eve" << endl;
  
  if (D == 23)
    cout << "Christmas Eve Eve" << endl;
  
  if (D == 22)
    cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
N,M = map(int, input().split())

K = []
S = []
for i in range(M):
    ks = list(map(int, input().split()))
    K.append(ks[0])
    S.append(ks[1:])

P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
    cnt = 0
    for i in range(M):
        on_cnt = 0
        for s in S[i]:
            if bit & (1 << (s-1)):
                on_cnt += 1

        if on_cnt % 2 == P[i]:
            cnt += 1
        
    if cnt == M:
        ans += 1


print(ans)


Measured memory_bytes: 3064
n = int(input())
a = [int(num) for num in input().split()]

a.sort()
first = 0
second = 0
i = 0
while i + 1 < n:
    #print(i)
    if (a[i] == a[i + 1]):
        second = first
        first = a[i]
        i += 1
    i += 1
        

print(first * second)

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

int main() {
 int N;
 cin >> N;
 vector<int> a(3*N);
  
  for(int i = 0; i < 3*N; i++) cin >> a.at(i);
   sort( a.begin(), a.end() );
   reverse( a.begin(), a.end() );
  
   int64_t ans = 0;
  
  for(int i = 1; i <= 2*N; i+=2){
     ans += a.at(i);
    }
  cout << ans << endl;
}

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

using namespace std;
int N;
int A[300];

int parent(int i)
{
	return i / 2;
}
int leftchild(int i)
{
	return 2 * i;
}
int rightchild(int i)
{
	return 2 * i + 1;
}
int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> A[i];
	}
	for (int i = 1; i <= N; i++)
	{
		int p = parent(i);
		int l = leftchild(i);
		int r = rightchild(i);
		cout << "node " << i << ": key = " << A[i];
		if (p > 0 && p <= N)
		{
			cout << ", parent key = " << A[p];
		}
		if (l > 0 && l <= N)
		{
			cout << ", left key = " << A[l];
		}
		if (r > 0 && r <= N)
		{
			cout << ", right key = " << A[r];
		}
		cout << ", " << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	ll X[200000], Y[200000];
	ll saishou = 1e9;
	ll saidai = 0;
	ll saishouY = 1e9;
	ll saidaiX = 0;
	rep(i, N) {
		cin >> X[i] >> Y[i];
		if (X[i] > Y[i]) swap(X[i], Y[i]);
		saishou = min(saishou, X[i]);
		saidai = max(saidai, Y[i]);
		saishouY = min(saishouY, Y[i]);
		saidaiX = max(saidaiX, X[i]);
	}

	ll kotae = (saidai - saishouY) * (saidaiX - saishou);

	ll ue = saidaiX;
	ll sita = 1e9;
	kotae = min(kotae, (ue - saishou) * (saidai - saishou));

	vector<pair<ll, ll>> V;
	rep(i, N) {
		V.pb(mp(X[i], Y[i]));
	}
	sort(V.begin(), V.end());

	rep(i, N) {
		kotae = min(kotae, (ue - min(sita, V[i].first)) * (saidai - saishou));
		sita = min(sita, V[i].second);
		ue = max(ue, V[i].second);
	}
	kotae = min(kotae, (ue - sita) * (saidai - saishou));

	co(kotae);

	Would you please return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  int N;
  cin >> N;
  vector<int>P(N);
  vector<int>X(N);
  REP(i, N) {
    cin >> P.at(i);
    X.at(i) = i + 1;
    //print(X.at(i));
  }
  vector<int>Q(N);
  REP(i, N) cin >> Q.at(i);

  int cnt = 0;
  int a, b;
  do{
    cnt++;
    REP(i, N){
      if(P.at(i) != X.at(i)) break;
      if(i == N - 1) a = cnt;
    }
    REP(i, N){
      if(Q.at(i) != X.at(i)) break;
      if(i == N - 1) b = cnt;
    }
  }while(next_permutation(X.begin(), X.end()));
//print(a);
//print(b);

ll ans = abs(a - b);
print(ans);

}

Measured memory_bytes: 256
n = input()

def dfs(i, f, s):
    if i == 3:
        return f+"=7" if s == 7 else ''
    return dfs(i+1, f+"+"+n[i+1], s+int(n[i+1])) or dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

print(dfs(0, n[0], int(n[0])))

Measured memory_bytes: 3060
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef pair<LL, LL> P;
typedef pair<P, P> PP;
const int MAX_V = 20010;
struct edge { LL to, cost; };
vector<edge> G[MAX_V];
LL d[MAX_V][5][210];//time place t remain
int n, m, x;
int room[MAX_V];
bool visited[MAX_V][5][210];
void dijkstra() {
	priority_queue<PP, vector<PP>, greater<PP>> pq;
	for (int i = 0; i < MAX_V; i++) {
		for (int j = 0; j <= 2; j++) {
			for (int k = 0; k < 210; k++) {
				d[i][j][k] = LINF;
				visited[i][j][k] = false;
			}
		}
	}
	d[0][0][x] = 0;
	pq.push(mp(mp(d[0][0][x], 0), mp(0, x)));
	while (pq.size()) {
		auto p = pq.top();
		pq.pop();
		int time = p.first.first;
		int place = p.first.second;
		int t = p.second.first;
		int remain = p.second.second;
		if (!visited[place][t][remain]) {
			visited[place][t][remain] = true;
			d[place][t][remain] = time;

			for (int i = 0; i < G[place].size(); i++) {
				if (remain - G[place][i].cost <= 0) {
					pq.push(mp(mp(time + G[place][i].cost, G[place][i].to), mp(room[G[place][i].to], room[G[place][i].to] == 1 ? 0 : x)));
				}
				else {
					if (room[G[place][i].to] == 1 || room[G[place][i].to] == t) {
						pq.push(mp(mp(time + G[place][i].cost, G[place][i].to), mp(t, room[G[place][i].to] == 1 ? remain - G[place][i].cost : x)));
					}
				}
			}
		}
	}
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m >> x;
	for (int i = 0; i < n; i++) {
		cin >> room[i];
	}
	int a, b;
	LL c;
	for (int i = 0; i < m; i++) {
		cin >> a >> b >> c;
		a--, b--;
		G[a].emplace_back(edge{ b,c });
		G[b].emplace_back(edge{ a,c });
	}
	dijkstra();

	LL ans = LINF;
	for (int j = 0; j <= 2; j++) {
		for (int k = 0; k <= x; k++) {
			ans = min(ans, d[n - 1][j][k]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 189788
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"



signed main()
{
    FAST;
    int t;
    t=1;
    
    while(t--)
    {
        int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
        int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
        int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
        int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
        int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
        
        string a;
        cin>>a;
        cout<<a[0]<<a[1]<<a[2]<<endl;
        
        
    }
        
    
    
    
    
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

const int mod = 1e9 + 7, inf = mod;
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );

struct Mint {
  int a;
  Mint(int _a = 0) : a(_a) {}
  friend ostream& operator << (ostream &out, const Mint &_) {
    out << _.a;
    return out;
  }

  bool operator == (const Mint &_) const { return a == _.a; }
  bool operator ! () const { return !a; }

  Mint operator + (const Mint &_) const {
    int ret = a + _.a;
    return ret < mod ? Mint(ret) : Mint(ret - mod);
  }
  Mint operator - (const Mint &_) const { return *this + Mint(mod - _.a); }
  Mint operator * (const Mint &_) const { return Mint( (int)( (LL)a * _.a % mod) ); }
  friend Mint& operator += (Mint &a, const Mint &b) { return a = a + b; }
  friend Mint& operator -= (Mint &a, const Mint &b) { return a = a - b; }
  friend Mint& operator *= (Mint &a, const Mint &b) { return a = a * b; }
  Mint& operator ++ () { return *this = *this + Mint(1); }
  Mint& operator -- () { return *this = *this - Mint(1); }

  template<class T> Mint binPow(T exp) const {
    Mint ret(1), c = *this;
    for (; exp; exp >>= 1, c *= c) if (exp & 1) ret *= c;
    return ret;
  }
};

struct Bit {
  vector<Mint> a;
  Bit(int nNode) { a.assign(nNode, Mint() ); }

  void upd(int pos, Mint val) {
    for (int i = pos; i < sz(a); i |= i + 1) a[i] += val;
  }
  Mint get(int pos) {
    Mint ret;
    for (int i = pos; ~i; i = (i & (i + 1) ) - 1) ret += a[i];
    return ret;
  }
};

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

  #ifdef FourLeafClover
  freopen("input", "r", stdin);
  #endif // FourLeafCLover

  int n, m; cin >> n >> m;
  vector<int> x(n);
  for (auto &i : x) cin >> i;
  vector<int> y(m);
  for (auto &i : y) cin >> i;

  vector<pair<int, int> > p(n);
  vector<int> ySet;
  for (int i = 0, j = 0; i < n; ++i) {
    while (j < m && y[j] < x[i]) ++j;
    p[i] = { j ? x[i] - y[j - 1] : inf, j < m ? y[j] - x[i] : inf };
    ySet.emplace_back(p[i].second);
  }
  sort(all(p), [&](const pair<int, int> &i, const pair<int, int> &j) {
       return make_pair(i.first, -i.second) < make_pair(j.first, -j.second); });
  p.erase(unique(all(p) ), p.end() );
  sort(all(ySet) ); ySet.erase(unique(all(ySet) ), ySet.end() );

  vector<Mint> f(sz(p) );
  Bit bit(sz(ySet) );
  for (int i = 0; i < sz(p); ++i) {
//    cerr << p[i].first << ' ' << p[i].second << '\n';
    int pos = (int)(lower_bound(all(ySet), p[i].second) - ySet.begin() );
    f[i] = Mint(1) + bit.get(pos - 1);
    bit.upd(pos, f[i]);
  }

  if (p.back().first == inf) {
    Mint ans;
    int lim = 0;
    for (int i = 0; i < sz(p); ++i) if (p[i].first == inf) { lim = p[i].second; break ; }
    for (int i = 0; i < sz(p); ++i) if (p[i].second ^ inf && p[i].second >= lim) ans += f[i];
    cout << ans << '\n';
  }
  else {
    Mint ans(1);
    for (int i = 0; i < sz(p); ++i) if (p[i].second ^ inf) ans += f[i];
    cout << ans << '\n';
  }

  return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
    return a / gcd(a, b) * b;
}

string IntToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

int main()
{
    int cnt = 0;
    int n, m, c;
    ci >> n >> m >> c;

    int a, b[30];

    rep(i, m) ci >> b[i];

    rep(i, n) {
	int sum = c;
	rep(j, m) {
	    ci >> a;
	    sum += a * b[j];
	}
	if(sum > 0) cnt++;
    }

    co << cnt << en;
  
    return 0;
}


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

const int mod = 1e9+7;
const int INF = 2000000;

int main() {
    int N;
    string a;
    set<string> s;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        s.insert(a);
    }
    cout << s.size() << endl;
    
}


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

int main(){

  int N,M;
  int x,y;
  int d=0;

  cin>>N;

  for(x=0;x<100;x++){
    for(y=0;y<100;y++){

    M=4*x+7*y;

    if(M==N){
      d=1;
      break;
    }
    }
  }

  if(d==1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256