akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() { T buf; cin >> buf; return buf; }

struct TT {
  int i, j, k;
  
  bool operator<(TT r) const {
    if (i != r.i) return i < r.i;
    if (j != r.j) return j < r.j;
    if (k != r.k) return k < r.k;
    return false;
  }
};

vector<long> s, t, u;
set<TT> st;
int main() {
  int a, b, c, z;
  cin >> a >> b >> c >> z;
  
  for (int i = 0; i < a; ++i) s.push_back(Next<long>());
  for (int i = 0; i < b; ++i) t.push_back(Next<long>());
  for (int i = 0; i < c; ++i) u.push_back(Next<long>());
  
  sort(s.rbegin(), s.rend());
  sort(t.rbegin(), t.rend());
  sort(u.rbegin(), u.rend());
  
  priority_queue<pair<long, TT>> Q;
  Q.push(make_pair(s[0] + t[0] + u[0], TT{ 0, 0, 0 }));
  
  int cnt = 0;
  while (cnt < z) {
    auto q = Q.top(); Q.pop();
    long sc = q.first;
    TT tt = q.second;
    int i = tt.i;
    int j = tt.j;
    int k = tt.k;
    if (st.count(tt)) continue;
    st.insert(tt);
    
    cout << sc << endl;
    if (i < a - 1) Q.push(make_pair(s[i + 1] + t[j] + u[k], TT{ i + 1, j, k }));
    if (j < b - 1) Q.push(make_pair(s[i] + t[j + 1] + u[k], TT{ i, j + 1, k }));
    if (k < c - 1) Q.push(make_pair(s[i] + t[j] + u[k + 1], TT{ i, j, k + 1 }));
    ++cnt;
  }
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    ArrayList<String> ans = new ArrayList<String>();
    String[] ab;
    while(true) {
      String line = sc.nextLine();
      if(line.length() == 0 || line.contains("0 0")) {
        break;
      }
      ab = line.split(" ");
      int a = Integer.parseInt(ab[0]);
      int b = Integer.parseInt(ab[1]);
      if(a < b) {
        ans.add(a + " " + b);
      }else {
        ans.add(b + " " + a);
      }
    }
    for(int i = 0; i < ans.size(); i++) {
      System.out.println(ans.get(i));
    }

  }
}



Measured memory_bytes: 36000
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cfloat>
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")

#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

const int N = 105;

int n, maxi, mini;
int a[N];

bool gao() {
    if (mini == 1 || maxi == 2) {
        if (n == 2) return (a[1] == 2);
        return (a[1] == 1) && (a[2] == n - 1);
    }

    int d, t = maxi / 2 + 1;
    FORD (i, maxi, t) {
        if (a[i] < 2) return 0;
        a[i] -= 2;
    }
    if (maxi % 2 == 0) {
        d = maxi / 2;
        if (a[d] < 1) return 0;
        a[d]--;
        t--;
    }
    if (maxi % 2) t = maxi / 2 + 1;
    else t = maxi / 2;
    FORD (i, t, 1) if (a[i] > 0) return 0;
    return 1;
}

int main() {
    int x, flag;
    while (~scanf("%d", &n)) {
        maxi = 0, mini = n - 1;
        memset(a, 0, sizeof(a));
        rep (i, n) {
            scanf("%d", &x);
            a[x]++;
            maxi = max(x, maxi);
            mini = min(mini, x);
        }
        flag = gao();
        puts(flag ? "Possible" : "Impossible");
    }
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}

int main()
{
  int n;cin>>n;
  vector<int> a(n,0);
  REP(i,n)
  {
    cin >> a[i];
    a[i]--;
  }
  int ans=0;
  REP(i,n) if(i==a[a[i]]) ans++;
  cout<<(ans/2)<<endl;
}


Measured memory_bytes: 640
package main

import "fmt"

func solve(n, m int) int {
	if n == 1 && m == 1 {
		return 1
	}

	if n == 1 {
		return m - 2
	}
	if m == 1 {
		return n - 2
	}

	return (n - 2) * (m - 2)
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	fmt.Println(solve(n, m))
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 55
#define INF 1000000009

int n;
string s[MAXN];
map<char, int> mp[MAXN];

int mn(int a, int b){
    return a < b ? a : b;
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        for(int j = 0; j < (int)s[i].size(); j++){
            mp[i][s[i][j]]++;
            mp[52][s[i][j]] = INF;
            if(mp[51][s[i][j]] == i){
                mp[51][s[i][j]] = i + 1;
            }
        }
    }
    map<char, int> :: iterator ite;
    for(int i = 0; i < n; i++){
        for(ite = mp[i].begin(); ite != mp[i].end(); ++ite){
            mp[52][ite->first] = mn(mp[52][ite->first], ite->second);
            //printf("mp[52][%c] = %d\n", ite->first, mp[52][ite->first]);
        }
    }
    for(ite = mp[52].begin(); ite != mp[52].end(); ++ite){
        if(ite->second > 0 && mp[51][ite->first] == n){
            for(int i = 0; i < ite->second; i++){
                printf("%c", ite->first);
            }
        }
    }

    printf("\n");



    return 0;
}


Measured memory_bytes: 256
// Aizu 1136: Polygonal Line Search
// 2017.9.14 bal4u@uu

#include <stdio.h>

typedef struct { int x, y; } PP;
typedef struct { int m; PP p[11]; } LN;
LN line[52]; int n;

void rot90(LN *ln)
{
	int i, x, y;
	for (i = 0; i < ln->m; i++) {
		x = ln->p[i].x, y = ln->p[i].y;
		ln->p[i].x = y, ln->p[i].y = -x;
	}
}

int match(LN *ln)
{
	int i, j, dx, dy;

	for (j = 0; j < 4; j++) {
		dx = ln->p[0].x - line[0].p[0].x, dy = ln->p[0].y - line[0].p[0].y;
		for (i = 1; i < ln->m; i++)
			if (ln->p[i].x - line[0].p[i].x != dx || ln->p[i].y - line[0].p[i].y != dy) break;
		if (i >= ln->m) return 1;
		rot90(ln);
	}
	return 0;
}

int main()
{
	int m, i, j;
	LN tmp1, tmp2;

	while(scanf("%d", &n) && n) {
		for (i = 0; i <= n; i++) {
			scanf("%d", &m); line[i].m = m;
			for (j = 0; j < m; j++) scanf("%d%d", &line[i].p[j].x, &line[i].p[j].y);
		}
		for (i = 1; i <= n; i++) {
			if ((m = line[0].m) != line[i].m) continue;
			tmp1 = line[i]; tmp2.m = m;	for (j = 0; j < m; j++)	tmp2.p[j] = line[i].p[m-1-j];
			if (match(&tmp1) || match(&tmp2)) printf("%d\n", i);
		}
		puts("+++++");
	}
	return 0;
}

Measured memory_bytes: 1760
splitBy :: Char -> String -> [String]
splitBy _ [] = []
splitBy a x =
  let s = takeWhile (/= a) x
      x'= dropWhile (/= a) x
  in
    if x' == []
    then [s]
    else s:(splitBy a $ drop 1 x')

int x =
  if x >= 0
  then floor x
  else ceiling x

ans _ (x,y) [] = (x,y)
ans ang (x,y) ([d,r]:xs) =
  let y' = y + d * (cos (pi*ang/180))
      x' = x + d * (sin (pi*ang/180))
      a' = ang + r
  in
    ans a' (x',y') xs

main = do
  c <- getContents
  let i = map (map read) $ map (splitBy ',') $ lines c :: [[Float]]
      o = ans 0 (0,0) i
      x = int $ fst o
      y = int $ snd o
  print x
  print y

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

constexpr int MAX = 200200;
constexpr int INF = (1 << 30);

int main() {
    int n;
    cin >> n;
    vector<int> a(n), g[n];
    for (int &e : a) cin >> e;
    for (int i = 0; i < n - 1; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        g[s].emplace_back(t);
        g[t].emplace_back(s);
    }
    
    vector<int> dp(MAX, INF), ans(n);
    stack<pair<int, pair<int, int>>> sta;
    sta.emplace(0, make_pair(0, 0));
    
    while (not sta.empty()) {
        int type = sta.top().first;
        if (type == 0) {
            auto [v, p] = sta.top().second;
            sta.pop();
            auto it = lower_bound(dp.begin(), dp.end(), a[v]);
            sta.emplace(1, make_pair(it - dp.begin(), *it));
            *it = a[v];
            ans[v] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
            for (int u : g[v]) if (u != p) sta.emplace(0, make_pair(u, v));
        } else {
            auto [id, val] = sta.top().second;
            sta.pop();
            dp[id] = val;
        }
    }
    
    for (int e : ans) cout << e << '\n';
    
    return 0;
}

Measured memory_bytes: 18808
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
sample_input = '''
3
4
3
2
'''
give_sample_input = False
if give_sample_input:
  sample_input_list = sample_input.split()
  def input():
    return sample_input_list.pop(0)

numOfData = int(input())
max_diff = None  # minus infty
min_val = None  # plus infty
prev_val = int(input())
for n in range(numOfData-1):
	val = int(input())
	if min_val is None:
		min_val = prev_val
	else:
		min_val = min(prev_val, min_val)
	if max_diff is None:
	  max_diff = val - min_val
	else:
	  max_diff = max(val - min_val, max_diff)
	prev_val = val

print(max_diff)

Measured memory_bytes: 7740
//@author yash
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define x first
//#define y second
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	fast();
	int n,r;
	cin>>n>>r;
	if(n>=10)
	cout<<r<<endl;
	else
	{
		cout<<r+(100*(10-n))<<endl;
			}		
}



Measured memory_bytes: 256
def merge(A, left, mid, right):
    count = 0
    L = A[left:mid]
    R = A[mid:right]
    L.append(1000000001)
    R.append(1000000001)
    i, j = 0, 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            if L[i] != 1000000001:
                count += mid + j - k - 1
    return count


def mergesort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        countL = mergesort(A, left, mid)
        countR = mergesort(A, mid, right)
        return merge(A, left, mid, right) + countL + countR
    return 0


def main():
    n = int(input())
    A = list(map(int, input().split()))
    ans = mergesort(A, 0, n)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27472
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(i,x) for(auto &i:x)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
    return l+rng()%(r-l+1);
}
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define pii pair<int,int>
#define fi first
#define se second
#define batbit(i,x) (x|(1ll<<i))
#define getbit(i,x) ((x>>i)&1)

const int mn=305;
int a[mn][mn],n,m,k,s[mn][mn],cnt,pre[mn][mn],p,dd[mn][mn];
pii d[mn*mn];

main()
{
    //freopen("test.inp","r",stdin);

    cin >> n >> m >> k;
    forinc(i,1,n)
    {
        forinc(j,1,m)
        {
            char ch;
            cin >> ch;
            a[i][j]=(ch=='#');
            if(a[i][j]) d[++p]={i,j};
        }
    }
    forinc(j,1,m)
    {
        int pos=0;
        forinc(i,1,n)
        {
            pre[i][j]=pos;
            if(a[i][j]) pos=i;
        }
    }
    forinc(t,1,p)
    {
        cnt++;
        int i=d[t].fi,j=d[t].se;
        if(pre[i][j]==0)
        {
            forinc(o,1,i)
            {
                dd[o][j]=cnt;
            }
        }
        int pos=0;
        forinc(p,i+1,n)
        {
            if(a[p][j])
            {
                pos=p-1;
                break;
            }
        }
        if(pos==0)
        {
            forinc(o,i,n) dd[o][j]=cnt;
        }
        else forinc(o,i,pos) dd[o][j]=cnt;
    }
    bool ok=true;
    while(ok)
    {
        ok=false;
        forinc(i,1,n)
        {
            forinc(j,1,m-1)
            {
                if(dd[i][j]==0&&dd[i][j+1]!=0)
                {
                    dd[i][j]=dd[i][j+1];
                }
            }
        }
        forinc(i,1,n)
        {
            fordec(j,m,2)
            {
                if(dd[i][j]==0&&dd[i][j-1]!=0)
                {
                    dd[i][j]=dd[i][j-1];
                }
            }
        }
        forinc(i,1,n)
        {
            forinc(j,1,m) if(!dd[i][j])
            {
                ok=true;
            }
        }
    }
    forinc(i,1,n)
    {
        forinc(j,1,m) cout << dd[i][j] << " ";
        cout << "\n";
    }
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, a[MAX_N][3], dp[MAX_N][3]{};
    cin >> n;
    REP(i,n)REP(j,3) cin >> a[i][j];
    REP(i,n){
        REP(j,3){
            dp[i+1][j] = max(dp[i][(j+1)%3],dp[i][(j+2)%3])+a[i][j];
        }
    }
    cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;
    return 0;
}


Measured memory_bytes: 2560
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    n = len(s)

    res = 0
    for i in range(1, n):
        if s[i - 1] != s[i]:
            res += 1
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define q_type vector<ll>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100010
#define M 400010
using namespace std;
template<typename T>inline void read(T &x)
{
	x=0;
	static int p;p=1;
	static char c;c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-'0');c=getchar();}
	x*=p;
}
int n,m;
int e;
int to[M],beg[N],nex[M],Belong[M];
void add(int x,int y,int c)
{
	to[++e]=y;
	nex[e]=beg[x];
	beg[x]=e;
	Belong[e]=c;
}
struct node
{
	int dis,s;
	bool operator <(const node &ss)const { return dis==ss.dis?s<ss.s:dis<ss.dis; }
};
int dis[N],vis[N];
set<int>C[N*10];
void Dijkstra()
{
	priority_queue<node>q;
	memset(dis,0x3f,sizeof dis);
	dis[1]=0;
	q.push((node){0,1});
	while(!q.empty())
	{
		node k=q.top();q.pop();
		if(vis[k.s])continue;
		vis[k.s]=1;
		for(int i=beg[k.s];i;i=nex[i])
		{
			int y=to[i];
			int w=C[k.s].count(Belong[i])?0:1;
			if(dis[y]>dis[k.s]+w)
			{
				dis[y]=dis[k.s]+w;
				C[y].clear();C[y].insert(Belong[i]);
				q.push((node){-dis[y],y});
			}
			else if(dis[y]==dis[k.s]+w)C[y].insert(Belong[i]);
		}
	}
	printf("%d\n",dis[n]==0x3f3f3f3f?-1:dis[n]);
}
int main()
{
	read(n);read(m);
	for(int i=1;i<=m;i++)
	{
		static int x,y,c;
		read(x);read(y);read(c);
		add(x,y,c);add(y,x,c);
	}
	Dijkstra();
	return 0;
}

Measured memory_bytes: 62712
#include <iostream>
#include <cstdio>
#include <cstring>
#define il inline
#define ri register
#define Size 400050
using namespace std;
namespace{
	template<class free>
		il void read(free&x){
		x^=x;ri char c;while(c=getchar(),c==' '||c=='\n'||c=='\r');
		ri bool check(false);if(c=='-')check=true,c=getchar();
		while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
		if(check)x=~x+1;
	}
	template<class f1,class...f2>
		il void read(f1&x,f2&...y){
		read(x),read(y...);
	}
}
struct graph{
	struct point{
		int next,to;
	}ar[Size];
	int head[Size],art;
	il void link(int u,int v){
		ar[++art]={head[u],v},head[u]=art;
	}
	il void link1(int u,int v){
		link(u,v),link(v,u);
	}
}T[2],G;
int son[2][Size],a[Size];
il int dfs(int,int);
il void dfs1(int,int);
int main(){
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	int n,rt[2];read(n);
	for(int i(0),j,k;i<2;++i)
		for(j=1;j<=n;++j)
			read(k),~k?T[i].link(k,j),
				++son[i][k]:rt[i]=j;
	for(int i(1);i<=n;++i)
		if(son[0][i]+son[1][i]&1)
			return puts("IMPOSSIBLE"),0;
	for(int i(0);i<2;++i)dfs(rt[i],i);
	for(int i(1);i<=n;++i)
		if(~son[0][i]&1&&!a[i])dfs1(i,1);
	puts("POSSIBLE");
	for(int i(1);i<=n;++i)printf("%d\n",a[i]);
	return 0;
}
il void dfs1(int x,int c){
	a[x]=c;
	for(int i(G.head[x]),i1;i;i=G.ar[i].next)
		if(!a[i1=G.ar[i].to])dfs1(i1,-c);
		else if(a[i1]==c)throw;
}
il int dfs(int x,int y){
	int last(0);
	for(int i(T[y].head[x]),i1;i;i=T[y].ar[i].next)
		i1=dfs(T[y].ar[i].to,y),last?
			G.link1(i1,last),last=0:last=i1;
	return son[y][x]&1?last:x;
}


Measured memory_bytes: 16768
n = int(input())
A = list(map(int, input().split()))

cnt = 0
m = 100000000000
ans = 0
for a in A:
    ans += abs(a)
    if a < 0:
        cnt += 1
    if abs(a) < m:
        m = abs(a)

if cnt % 2 == 0:
    print(ans)
else:
    print(ans - 2 * m)


Measured memory_bytes: 14284
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, a, b, cnt = 0;
    cin >> n;
    vector<int> p(n), q(n), s(n);
    for (int i = 0; i < n; ++i) cin >> p.at(i);
    for (int i = 0; i < n; ++i) cin >> q.at(i);
    iota(s.begin(), s.end(), 1);
    do {
        if (s == p) a = cnt;
        if (s == q) b = cnt;
        ++cnt;
    } while (next_permutation(s.begin(), s.end()));
    cout << abs(a - b) << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = gets.split.map(&:to_i)

ans = n-1
max = (n-1) * (n-2) / 2

if max < k
	puts "-1"
	exit
end

ans += max - k

puts ans

n.downto(2) do |i|
	puts "1 #{i}"
end

count = n-1
(2...n).each do |x|
	(x...n).each do |y|
		exit if count == ans
		puts "#{x} #{y+1}"
		count += 1
	end
end

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

long long ans;

void calc(long long a, long long b) {
	if (a % b == 0) {
      ans += (a * 2) - b;
      return;
    }
  ans += (a / b) * b * 2;
  calc(b, a % b);
}

int main() {
  long long n, x;
  cin >> n >> x;
  ans = n;
  if (x < n - x)
    x = n - x;
  calc(x, n - x);
  	cout << ans;
 	return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int dx[4] = {0,-1,0,1};
int dy[4] = {-1,0,1,0};


ll gcd(ll a,ll b){
    if(b>a) swap(a,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;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}


struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }

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


int main(){
 
    int n,m;
    cin >> n >> m;
    UnionFind uf(n+1);

    int ans = 0;

    rep(i,m){
        int a,b;
        cin >> a >> b;
        uf.unite(a,b);
    }

    
    for(int i = 1; i <= n; i++){
        int num = uf.size(i);
        ans = max(ans,num);
        //cout << uf.size(i) <<endl;

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


Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  if(a-b <0){
    cout <<c*a <<endl;
  }
  else{
    cout <<b*c+(a-b)*d <<endl;
  }
  
}

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

int main(){
	int n,scoreT=0,scoreH=0;
	string cardT,cardH;
	cin>>n;
	rep(i,0,n){
		cin >> cardT >> cardH;
		if(cardT>cardH) scoreT += 3;
		else if(cardH>cardT) scoreH += 3;
		else{
			scoreT += 1;
			scoreH += 1;
		}
	}
	cout << scoreT << " " << scoreH << endl;
	return 0;
}


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

using namespace std;

#define N 10
#define INF (1e9)

int main(){
    int M,a,b,c;
    while(cin >> M, M){
        int d[N][N],mx = 0;
        fill(d[0],d[N],INF);
        for(int i = 0 ; i < M ; i++){
            cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
            mx = max(mx,max(a,b));
        }
        mx++;
        for(int i = 0 ; i < mx ; i++){
            d[i][i] = 0;
        }
        for(int k = 0 ; k < mx ; k++){
            for(int i = 0 ; i < mx ; i++){
                for(int j = 0 ; j < mx ; j++){
                    d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
        int res = INF,vnum = -1;
        for(int i = 0 ; i < mx ; i++){
            int sum = 0;
            for(int j = 0 ; j < mx ; j++){
                sum += d[i][j];
            }
            if(sum < res){
                res = sum;
                vnum = i;
            }
        }
        cout << vnum << " " << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007


int main()
{
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if((j < a && i < b) || (j >= a && i >= b)){
				cout << "1";
			} else {
				cout << "0";
			}
		}
		cout << endl;
	}
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a,b,c,d,add,ans;
int x[10];
signed main(){
	for (register int i=1; i<=7; ++i) scanf("%lld",&x[i]);
	a=x[1]; b=x[2]; c=x[4]; d=x[5];
	ans=b;
	add=a/2*2+c/2*2+d/2*2;
	if (a && c && d)
	{
		if (a%2==c%2 && a%2==d%2) add=max(add,a+c+d);
		else add=max(add,a+c+d-1);
	}
	ans+=add;
	printf("%lld\n",ans);
return 0;
}

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

public class Main {

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

  private void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int heapSize = Integer.parseInt(br.readLine());
      String[] keys = br.readLine().split(" ");
      long[] heap = new long[heapSize+1];
      for(int i=1; i<=heapSize; i++)
        heap[i] = Integer.parseInt( keys[i-1] );

      StringBuilder buf = new StringBuilder();
      for(int i=1; i<=heapSize; i++){
        buf.append("node " + i + ": key = " + heap[i] + ", ");
        if( i != 1 ) buf.append("parent key = " + heap[i/2] + ", ");
        if( i*2 <= heapSize) {
          buf.append("left key = " + heap[i*2] + ", ");
          if( i*2+1 <= heapSize) {
            buf.append("right key = " + heap[i*2+1] + ", ");
          }
        }
        buf.append("\n");
      }

      System.out.print(buf);
    } catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}


Measured memory_bytes: 24188
import java.util.Scanner;

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

		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int[] A = new int[M];

		for (int i = 0; i < M; i++) {
			A[i] = sc.nextInt();
		}
		int toZero = 0;
		int toN = 0;
		for (int a : A) {
			if (a > X) {
				toZero = toZero + 1;
			} else {
				toN = toN + 1;
			}
		}
		System.out.println(toZero > toN ? toN : toZero);

	}
}


Measured memory_bytes: 22996
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x) cin >> x
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int A, B, T;
    in(A);
    in(B);
    in(T);

    ll count = 0;

    for (int t = A; t <= T; t += A)
    {
        count += B;
    }

    outl(count);

    return 0;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
s = str(n)
K = int(input())
l = len(str(n))

# dp[loose/tight][count][length]
dp = [[[0] * l for _ in range(K + 2)] for _ in range(2)]
for i, item in enumerate(s):
    val = int(item)
    # Initialize
    if i == 0:
        dp[0][0][i] = 1
        for j in range(1, 10):
            if j < val:
                dp[0][1][i] += 1
            if j == val:
                dp[1][1][i] += 1
        continue
    for j in range(10):
        is_not_zero = j != 0
        if val == j:
            for k in range(K+1):
                dp[0][k+is_not_zero][i] += dp[0][k][i-1]
                dp[1][k+is_not_zero][i] += dp[1][k][i-1]
        elif j < val:
            for k in range(K+1):
                dp[0][k+is_not_zero][i] += dp[0][k][i-1] + dp[1][k][i-1]
        else:
            for k in range(K+1):
                dp[0][k+is_not_zero][i] += dp[0][k][i-1]

print(dp[0][K][-1] + dp[1][K][-1])

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            for(int i = A;i<= B; i++)
            {
                if(i%K == 0)
                {
                    Console.WriteLine("OK");
                    return;
                }
            }
            Console.WriteLine("NG");
        }
    }
}


Measured memory_bytes: 27536
## main

while line = gets
  chs = line.strip.split('')

  prv2 = ''
  prv1 = ''

  njoi = nioi = 0

  for ch in chs
    if ch == 'I' && prv1 == 'O'
      if prv2 == 'J'
        njoi += 1
      elsif prv2 == 'I'
        nioi += 1
      end
    end

    prv2 = prv1
    prv1 = ch
  end

  puts njoi
  puts nioi
end

Measured memory_bytes: 6176
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
import numpy as np
H,W=map(int,input().split(' '))
c = np.array([list(map(int,input().split(' '))) for i in range(10)])
A = [list(map(int,input().split(' '))) for i in range(H)]
csr = csr_matrix(c)
cost  = dijkstra(csr)
ans = 0
for i in A:
    for j in i:
        if j != -1:
            ans += cost[j][1]
print(int(ans))

Measured memory_bytes: 17784
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int ans = 0;
  ans += a-1;
  if (b>=a) ans++;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string>) {}
template<typename T1,typename T2> ostream& operator<<(ostream& os, pair<T1,T2> buf) {
  return os << "(" << buf.first << ": " << buf.second << ")"; }
#define DefOut(Con) template<typename T>ostream&operator<<(ostream&os,Con<T>&A){ bool f = false; os << "{"; \
  for (const auto e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
#define DefOut2(Con) template<typename K,typename V>ostream&operator<<(ostream&os,Con<K,V>&A) \
{ bool f = false; os << "{"; for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
template<typename T>ostream &operator << (ostream &os,vector<vector<T>>& A) {
  for (auto &B: A) os << '\n' << B; return os; }
DefOut(vector) DefOut(set) DefOut(multiset) DefOut2(map) 
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1000000007;
long long const INF = 1e18;
#define PI 3.14159265358979323846
/***********************************************************************/

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  cin >> s;
  if (SZ(s) < 3) kek(0);
  i64 ans = 0;
  int i = 0;
  int n = SZ(s);
  int as = 0;
  while (i < n) {
    while (i < n && s[i] != 'A') ++i, as = 0;
    while (i < n && s[i] == 'A') {
      as++;
      ++i;
    }
    while (i < n + 1 && s.substr(i, 2) == "BC") {
      ans += as;
      i += 2;
    }
  }
  kek(ans);
  
  return 0;
}


Measured memory_bytes: 720
inf = float('inf')
V,E,P = map(int,input().split())
edge = []
edge_rev = []
for i in range(E):
    A,B,C = map(int,input().split())
    edge_rev.append([B-1,A-1,P-C])
    edge.append([A-1,B-1,P-C])

d = [inf]*V
d[0] = 0
for i in range(V):
    update = False
    for j in range(E):
        From,To,cost = edge[j]
        if d[From] != inf and d[To]>d[From]+cost:
            d[To]=d[From]+cost
            update = True
    if not update:
        break

d_rev = [inf]*V
d_rev[V-1] = 0
for i in range(V):
    update = False
    for j in range(E):
        From,To,cost = edge_rev[j]
        if d_rev[From] != inf and d_rev[To]>d_rev[From]+cost:
            d_rev[To]=d_rev[From]+cost
            update = True
    if not update:
        break

d_ = [x for x in d]
d_rev_ = [x for x in d_rev]



for j in range(E):
    From,To,cost = edge[j]
    if d[From] != inf and d_rev[From] != inf and d[To]>d[From]+cost:
        d[To]=d[From]+cost


for j in range(E):
    From,To,cost = edge_rev[j]
    if d[From] != inf and d_rev[From] != inf and d_rev[To]>d_rev[From]+cost:
        d_rev[To]=d_rev[From]+cost


loop = False
for i in range(V):
    if d[i] != 0 and d_rev[i] != 0:
        loop = (d[i]+d_rev[i] != d_[i]+d_rev_[i]) or loop

if loop:
    print(-1)

else:
    ans = -d[-1]
    print(max(0,ans))

Measured memory_bytes: 57816
/*
 * hoge.cpp
 *
 *  Created on: 2014/09/30
 *      Author: eiichi
 */
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<list>
using namespace std;

vector<int> split(string s,char c){
	vector<int> v;string tmp;
	for(int i=0;i<s.size();i++){
		if(s[i]==c){
			v.push_back(stoi(tmp));
			tmp ="";
		}
		else tmp += s[i];
	}
	if(tmp!="")v.push_back(stoi(tmp));
	return v;
}

int main(void){
	int mat[2][101][101];
	int n,m,l;
	cin >> n >> m >> l;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin >> mat[0][i][j];
	for(int i=0;i<m;i++)
		for(int j=0;j<l;j++)
			cin >> mat[1][i][j];

	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			long long sum=0;
			for(int k=0;k<m;k++){
				sum += mat[0][i][k]*mat[1][k][j];
			}
			cout << sum;
			if(j!=l-1)cout << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	int K;
	cin >> S;
	cin >> K;
	int a = 1;
	for (int i = 0; i < K; i++) {
		if (S[i] != '1') {
			a = S[i] - '0';
			break;
		}
	}

	cout << a << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

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

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

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

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


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()

typedef pair<double,double> pdd;
typedef pair<double,pair<pii,int> > P;
#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
#define prev S.F.F
#define next S.F.S
#define state S.S
#define time F
double vis[1<<16][20];
void mainmain(){
	int n;
	cin>>n;
	vint id(n);
	vector<pdd> v(n);
	rep(i,n){
		cin>>id[i]>>v[i].F>>v[i].S;
	}
	priority_queue<P> pq;
	rep(i,n) pq.push(mkp(0.0,mkp(mkp(19,i),0)));
	rep(i,1<<16){
		rep(j,16) vis[i][j]=-1;
	}
	vint ans;
	while(!pq.empty()){
		P top=pq.top();
		pq.pop();
		if(vis[top.state][top.next]!=-1) continue;
		vis[top.state][top.next]=top.prev;
		top.state|=1<<top.next;
		if(top.state==(1<<n)-1){
			ans.PB(top.next);
			break;
		}
		int w=0;
		rep(i,n){
			if(top.state&(1<<i)) w+=v[i].S;
		}
		w*=20;
		double fa=2000.0/(70.0+w);
		rep(i,n){
			if((1<<i)&top.state) continue;
			P tmp=top;
			tmp.time-=(double)abs(v[top.next].F-v[i].F)/fa;
			tmp.prev=top.next;
			tmp.next=i;
			pq.push(tmp);
		}
	}
	int aa=1<<n;
	aa--;
	while(ans.size()<n){
		aa-=1<<ans.back();
		ans.PB(vis[aa][ans.back()]);
	}
	reverse(ALL(ans));
	rep(i,n){
		if(i) cout<<" ";
		cout<<id[ans[i]];
	}
	cout<<endl;
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 36760
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		long[] pow = new long[120];
		for(int i = 0; i < 120; i++) {
			long a = (long)i;
			pow[i]=a*a*a*a*a;
			//System.out.println(pow[i]);
		}
		int a = 0;
		int b = 0;
		for(int i = 0; i < 120; i++) {
			long powa = pow[i];
			for(int j = 0; j < 120; j++) {
				long powb = pow[j];
				if(powa-powb==(long)x) {
					a = i;
					b = j;
					break;
				}
				if(powa+powb==(long)x) {
					a = i;
					b = -j;
					//System.out.println(a);
					break;
				}
			}
			if(a!=0||b!=0)break;
		}
		if(a!=0||b!=0) {
			System.out.println(a+" "+b);
		}
	 }
}

Measured memory_bytes: 38876
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int m, k;
    cin >> m >> k;
    if((1 << m) <= k){
        cout << -1 << endl;
        return 0;
    }
    if(m == 1 && k == 1){
        cout << -1 << endl;
        return 0;
    }
    if(m == 1 && k == 0){
        cout << 0 << ' ' << 0 << ' ' << 1 << ' ' << 1 << endl;
        return 0;
    }
    vector<int> ans;
    ans.push_back(k);
    rep(i, 0, 1 << m){
        if(i == k) continue;
        ans.push_back(i);
    }
    ans.push_back(k);
    for(int i = (1 << m) - 1; i >= 0; i--){
        if(i == k) continue;
        ans.push_back(i);
    }
    for(int ii = 0; ii < ans.size(); ii++){
        if(ii) cout << ' ';
        cout << ans[ii];
    }
    cout << endl;
}

Measured memory_bytes: 4080
N = int(input())
s = []
t = []
ans = 0
for i in range(N):
    S = input()
    s.append(S)
M = int(input())
for i in range(M):
    T = input()
    t.append(T)    
for k in range(N):
    cnt = s.count(s[k])-t.count(s[k])
    ans = max(ans,cnt)
print(ans)


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

/* clang-format off */
#define int long long
#define double long double
struct Fast {Fast() {cin.tie(0); ios::sync_with_stdio(false);}} fast;

template <typename T> inline size_t maxElement(T beginIt, T endIt) { return max_element(beginIt, endIt); }
template <typename T> inline size_t minElement(T beginIt, T endIt) { return min_element(beginIt, endIt); }
template <typename T> inline size_t maxIndex(T beginIt, T endIt) { return distance(beginIt, *max_element(beginIt, endIt)); }
template <typename T> inline size_t minIndex(T beginIt, T endIt) { return distance(beginIt, *min_element(beginIt, endIt)); }
template <typename T> inline int sum(T beginIt, T endIt) { return accumulate(beginIt, endIt, 0); }
template <typename T> inline int mean(T beginIt, T endIt) { return sum(beginIt, endIt) / distance(beginIt, endIt); }
template <typename T> inline void debug(T x) { cerr << x << " " << "(L:" << __LINE__ << ")" << endl; }
/* clang-format on */

signed main(void) {
  /* */
  int num;
  num = 0; // count
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  // array<int, 200000> A;
  // string S;
  /* */

  int a, b;

  cin >> a >> b;

  if (a * b == 15) cout << "*" << endl;
  else if (a + b == 15) cout << "+" << endl;
  else cout << "x" << endl;

  // cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
def t(n):
  return n-c
a,b,c=map(int,input().split())
L=[b]*a
for i in range(c):
  P=int(input())
  L[P-1]+=1
L=list(map(t,L))
for i in range(a):
  if L[i]<=0:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 9892
n1 = [int(i) for i in input().split()]
n2 = [int(i) for i in input().split()]


class Dice(object):
    def __init__(self,num):
        self.n = num[4]
        self.e = num[2]
        self.w = num[3]
        self.s = num[1]
        self.center = num[0]
        self.back = num[5]

    def number(self):
        number = [self.center, self.s, self.e, self.w, self.n, self.back]
        return number

    def move(self,str):
        if str == 'N':
            x = self.n
            self.n = self.center
            self.center = self.s
            self.s = self.back
            self.back = x
            return self.center
        elif str == 'S':
            x = self.s
            self.s = self.center
            self.center = self.n
            self.n = self.back
            self.back = x
            return self.center
        elif str== 'E':
            x = self.e
            self.e = self.center
            self.center = self.w
            self.w = self.back
            self.back = x
            return self.center
        elif str == 'W':
            x = self.w
            self.w = self.center
            self.center = self.e
            self.e = self.back
            self.back = x
            return self.center

dice1 = Dice(n1)
dice2 = Dice(n2)
bool = False
status = dice1.center


for i in range(4):
    for j in range(4):
        for k in range(4):
            # print(dice1.number(), dice2.number())
            if dice1.number() == dice2.number():
                bool = True
            else:
                dice1.move('N')
                dice1.move('E')
                dice1.move('S')
        dice1.move('E')
    dice1.move('N')




print('Yes') if bool == True else print('No')

Measured memory_bytes: 7884
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] n = new int[5];
        for(int i=0;i<5;i++){
            n[i] = sc.nextInt();
        }
        Arrays.sort(n);
        for(int i=0;i<5;i++){
            if(i!=0)System.out.print(" ");
            System.out.print(n[4-i]);
        }
        System.out.println();
    }
}

Measured memory_bytes: 17172
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
map<ll,ll>mp;
int main()
{
    ll n,sum=0,x,y;
    cin>>n;
    ll a[n];
    com(i,n)
    {
        cin>>a[i];
        mp[a[i]]++;
        sum+=a[i];
    }
    int q;
    cin>>q;
    com(i,q)
    {
        cin>>x>>y;
        mp[y]+=mp[x];
        sum-=(mp[x]*x);
        sum+=(mp[x]*y);
        mp[x]=0;
        cout << sum << endl;
    }
}

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

int main(){
	// おまじない
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int N;
    string S;
	// 出入力
	cin >> N;
    cin>>S;
    int ans=0;
    for(int i=0;i<S.length()-2;i++){
        if(S.substr(i,3)=="ABC"){
            ans++;
        }
    }
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    s = input()
    ans = c = s[1:].count("E")
    for i in range(1, n):
        if s[i - 1] == "W":
            c += 1
        if s[i] == "E":
            c -= 1
        ans = min(ans, c)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3676
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
ll K;

int main()
{
	char s[1005];
	int i=0;
	while(true){
		scanf("%c",&s[i]);
		if(s[i]=='\n')break;
		i++;
	}
	int w;
	scanf("%d",&w);
	for(int j=0;j<i;j+=w){
		printf("%c",s[j]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128