akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	// he, his, hat は全て't'より若い文字コードを持つ
	private static final int[] PATTEN_THE_ = { 0, -12, -15 };
	private static final int[] PATTEN_THIS = { 0, -12, -11, -1 };
	private static final int[] PATTEN_THAT = { 0, -12, -19, 0 };

	private static enum WORD {
		THE_, THIS, THAT, OTHER
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		Scanner sc;
		ArrayList<String> words;

		while ((line = br.readLine()) != null) {
			sc = new Scanner(line);
			words = new ArrayList<String>();
			while (sc.hasNext()) {
				words.add(sc.next());
			}
			for (String word : words) {
				String check = word.replace(".", "");
				WORD pattern = WORD.OTHER;
				int shift;
				if (check.length() == 3) {
					pattern = checkPattern(check, PATTEN_THE_);
				} else if (check.length() == 4) {
					pattern = checkPattern(check, PATTEN_THIS);
					if (pattern != WORD.THIS)
						pattern = checkPattern(check, PATTEN_THAT);
				}
				if (pattern == WORD.THE_ || pattern == WORD.THIS
						|| pattern == WORD.THAT) {
					shift = getNumberOfShift(word.charAt(0));
					System.out.println(decode(line, shift));
					break;
				}
			}
		}
	}

	public static WORD checkPattern(String word, int[] pattern) {

		WORD result = WORD.OTHER;

		boolean isMatch = false;

		int first = word.charAt(0);
		for (int i = 1; i < word.length(); i++) {
			int target = (int) word.charAt(i);
			if (target > first)
				target -= 26;
			if (target - first == pattern[i]) {
				isMatch = true;
			} else {
				isMatch = false;
				break;
			}
		}
		if (isMatch) {
			if (pattern == PATTEN_THE_)
				result = WORD.THE_;
			if (pattern == PATTEN_THIS)
				result = WORD.THIS;
			if (pattern == PATTEN_THAT)
				result = WORD.THAT;
		}
		return result;
	}

	public static int getNumberOfShift(char charOft) {
		int result;
		result = (int) charOft - (int) 't';
		return result;
	}

	public static String decode(String line, int shift) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < line.length(); i++) {
			char ch = line.charAt(i);
			if (ch >= 'a' && ch <= 'z') {
				ch = (char) ((int) ch - shift);
				if (ch < 'a')
					ch = (char) ((int) ch + 26);
				if (ch > 'z')
					ch = (char) ((int) ch - 26);
			}
			sb.append(ch);
		}
		return sb.toString();
	}
}

Measured memory_bytes: 15412
#include <stdio.h>

int n, m, x, a;
int b=0, f=0;

int main(){
    scanf("%d %d %d", &n, &m, &x);
    for(int i=0; i<m; i++){
        scanf("%d", &a);
        if(a < x)
            b+=1;
        else
            f += 1;
    }
    if(b<f)
        printf("%d\n", b);
    else
        printf("%d\n", f);
}


Measured memory_bytes: 128
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int t = stdIn.nextInt();
			if(t == 0)
			{
				break;
			}
			int n = stdIn.nextInt();
			int sum = 0;
			while(n-- != 0)
			{
				int s = stdIn.nextInt();
				int f = stdIn.nextInt();
				sum += f - s;
			}
			if(sum >= t)
			{
				System.out.println("OK");
			}
			else
			{
				System.out.println(t - sum);
			}
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int N, ans; cin >> N;
	string s, t; cin >> s >> t;
	if (s == t)ans = N;
	else {
		int num = 0;
		rep(i, N) {
			if (s.substr(N - i - 1, i + 1) == t.substr(0, i + 1))num = i + 1;
		}ans = 2 * N - num;
	}
	cout << ans << endl;
	cin >> N;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll x, y;
	cin>>x>>y;
	int ret = 1;
	while(2*x <= y){
		x *= 2;
		ret++;
	}
	cout<<ret<<endl;

	return 0;
}

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

c = 0
loc = 0
locs = {0: 0}
ini = 0

while True:
    c += 1
    loc = a[loc] - 1
    
    if c == k:
        print(loc + 1)
        break
    if loc in locs:
        ini = locs.get(loc)
        break
    locs[loc] = c

if c != k:
    rest = int((k - ini) % (c - ini))
    if rest <= 0:
        print(loc + 1)
    else:
        d = 0
        while True:
            d += 1
            loc = a[loc] - 1
            if d == rest:
                print(loc + 1)
                break



Measured memory_bytes: 104460
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i] + 1] = i;
  }
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->second + 1 << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 5888
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 0;
		int a = 0;
		int number = 0;

		for(int j=1; j<=N; j++) {
			//int number = 0;
			int l = String.valueOf(j).length();
			int jsum = 0;
			for(int k=0; k<l; k++) {
				jsum += Character.getNumericValue(String.valueOf(j).charAt(k));
			}
			if(A <=jsum && jsum <= B) {
				number += j;
			}
			ans = number;
		}
		a = ans;
		System.out.println(a);
	}

}


Measured memory_bytes: 23508
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
using namespace std;

int main()
{
	string op;
	int num;
	priority_queue<int>pq;
	while (cin >> op)
	{
		if (op == "end") break;
		if (op == "insert")
		{
			cin >> num;
			pq.push(num);
		}
		else if (op == "extract")
		{
			cout << pq.top() << endl;
			pq.pop();
		}
	}
}

Measured memory_bytes: 5716
#include <stdio.h>

#define MAX 2000000

int H,A[MAX+1];

int parent(int i){
  return i / 2;
}

int left(int i){
  return 2 * i;
}

int right(int i){
  return 2 * i + 1;
}

void maxHeapify(int i){
  int l,r,largest,tmp;
  l=left(i);
  r=right(i);
  if(l<=H && A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest]) largest=r;
  if(largest != i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}


int main(){
  int i;

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=H/2;i>=1;i--) maxHeapify(i);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");



  return 0;
}



Measured memory_bytes: 3700
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cstdio>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;
const ll mod = 1000000007;


string S;

int main()
{
	int ans = 0;
	cin >> S;
	for (int i = 0; i < S.length() / 2; i++)
	{
		if (S[i] != S[S.length() - i - 1])
		{
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
int a,b;

int main(){
    cin >> a >> b;
    int ans = 0;
    ans += max(a,b);
    if(a == max(a,b)) a -= 1;
    else b -=1;
    ans += max(a,b);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        HashMap<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            map.put(i, new ArrayList<>());
        }
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt();
            List<Integer> list = map.get(a[i]);
            list.add(i);
        }
        if (map.get(1).isEmpty()) {
            System.out.println(-1);
            return;
        }
        int current = -1;
        int count = 0;
        Comparator<Integer> comparator = new UpperBoundComparator<>();
        for (int i = 1; i <= N; i++) {
            List<Integer> list = map.get(i);
            if (list.isEmpty()) {
                break;
            }
            int x = ~Collections.binarySearch(list,  current, comparator);
            if (list.size() <= x) {
                break;
            }
            current = list.get(x);
            count += 1;
        }
        System.out.println(N-count);
    }
    class UpperBoundComparator<T extends Comparable<? super T>> implements Comparator<T> {
        public int compare(T x, T y) {
            return (x.compareTo(y) > 0) ? 1 : -1;
        }
    }
}


Measured memory_bytes: 123928
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
mii cnt[2];
vii v[2];
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		int temp;
		cin>>temp;
		cnt[i%2][temp]++;
	}
	for(int i=0; i<2; i++)
	{
		for(auto temp: cnt[i]) v[i].eb(temp.se, temp.fi);
		v[i].eb(0, -1);
		sort(begin(v[i]), end(v[i]));
	}
	int ans=0;
	for(int i=v[0].size()-1; i>=max((int)v[0].size()-100, 0); i--)
	{
		for(int j=v[1].size()-1; j>=max((int)v[1].size()-100, 0); j--)
		{
			if(v[0][i].se!=v[1][j].se) ans=max(ans, v[0][i].fi+v[1][j].fi);
		}
	}
	cout<<n-ans;
}




Measured memory_bytes: 6136
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] c = new int[n - 1];
            int[] s = new int[n - 1];
            int[] f = new int[n - 1];


            for (int i = 0; i < n - 1; i++) {
                c[i] = in.nextInt();
                s[i] = in.nextInt();
                f[i] = in.nextInt();
            }

            for (int i = 0; i < n - 1; i++) {
                int time = 0;
                for (int j = i; j < n - 1; j++) {
                    if (time < s[j]) {
                        time = s[j] + c[j];
                    } else {
                        if (time % f[j] != 0) {
                            time += f[j] - (time % f[j]);
                        }
                        time += c[j];
                    }
                }
                out.println(time);
            }

            out.print(0);
        }

    }
}



Measured memory_bytes: 27504
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S; cin >> S;
    if (S.substr(0, 4) == "YAKI") {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3584
s = input()
t = input()

r1 = {}
r2 = {}

for i in range(len(s)):
    c = s[i]
    if c not in r1:
        r1[c] = t[i]
    else:
        if r1[c] != t[i]:
            print("No")
            exit()

for i in range(len(s)):
    c = t[i]
    if c not in r2:
        r2[c] = s[i]
    else:
        if r2[c] != s[i]:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 41804
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	int A,B;
	scanf("%d %d",&A,&B);
	char arr[A+B];
	scanf("%s",arr);
	if(arr[A]!='-'){
		printf("No");
		return 0;
	}
	// check1
	for(int i=0;i<A;i++){
		if(arr[i]=='-'){
			printf("No");
			return 0;
		}
	}
	// check2
	for(int i=A+1;i<A+B;i++){
		if(arr[i]=='-'){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}


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

using namespace std;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	if (n < m) {
		printf("1");
		return 0;
	}
	if (n % m == 0) {
		printf("%d", n / m);
		return 0;
	}
	printf("%d", n / m + 1);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define M 100005
using namespace std;
int n;
int dp[M][3];
int main(){
    //freopen("data.inp", "r", stdin);
    //freopen("data.out", "w", stdout);
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        for(int j = 0; j < 3; ++j)
            scanf("%d", &dp[i][j]);
    for(int i = 1; i <= n; ++i){
        dp[i][0] += max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] += max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] += max(dp[i - 1][0], dp[i - 1][1]);
    }
    printf("%d", max(max(dp[n][0], dp[n][1]), dp[n][2]));
    return 0;
}

Measured memory_bytes: 4888
#include<bits/stdc++.h>
using namespace std;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
 
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}

typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
typedef long long int64;
const int64 INF = 1LL << 59;
struct edge{
  int to, cost;
};
typedef vector< vector< edge > > Graph;
void add_edge(Graph& info, int u, int v, int cost, bool flag = true){
  info[u].push_back( (edge){ v, cost});
  if(flag) info[v].push_back( (edge){ u, cost});
}
int64 Dijkstra(Graph& info, int s, int g, int X, vector< int >& H) { //sからgへの最短路
  typedef pair< int64, int > Pi;
  priority_queue< Pi > que;
  que.push( Pi( X, 0));
  // なるべく高い位置で移動するようにする
  vector< int64 > max_height(H.size(), -INF);
  max_height[0] = X;
  while(!que.empty()) {
    Pi p = que.top(); que.pop();
    if(p.second == H.size() - 1) return X + H[H.size() - 1] - p.first * 2;
    if(max_height[p.second] > p.first) continue;
    for(int i = 0; i < info[p.second].size(); i++){
      edge& e = info[p.second][i];
      if(e.cost > H[p.second]) continue; // いけない
      if(max_height[e.to] < min< int64 >( H[e.to], p.first - e.cost)){
        que.push( Pi( min< int64 >( H[e.to], p.first - e.cost), e.to));
        max_height[e.to] = min< int64 >( H[e.to], p.first - e.cost);
      }
    }
  }
  return -1;
}

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  vector< int > H(N);
  cin >> H;
  Graph info(N);
  for(int i = 0; i < M; i++){
    int a, b, t;
    cin >> a >> b >> t;
    a--, b--;
    add_edge( info, a, b, t); 
  }
  cout << Dijkstra( info, 0, N - 1, X, H) << endl;
}

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(long long N, long long M, std::vector<long long> A) {
  ll date = 0;
  rep(i,M){
    date += A[i];
  }
  if(date>N) cout << -1 << endl;
  else cout << N- date << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long N;
  std::cin >> N;
  long long M;
  std::cin >> M;
  std::vector<long long> A(M);
  for (int i = 0; i < M; i++) {
    std::cin >> A[i];
  }
  solve(N, M, std::move(A));
  return 0;
}


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

int main()
{
  int n,a,b,c;

  cin >> n;

  while(n--)
    {
      cin >> a >> b >> c;

      if(a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b)
	{
	  cout << "YES" << endl;
	}
      else
	{
	  cout << "NO" << endl;
	}
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

int ctoi(char c) {if (c >= '0' && c <= '9') {return c - '0';}return 0;}

int main() {
  ll a;
  string b;
  cin >> a >> b;
  a = a * ctoi(b[0]) * 100 + a * ctoi(b[2]) * 10 + a * ctoi(b[3]);
  cout << a / 100 << endl;
  return 0;
}

Measured memory_bytes: 3628
import itertools
import numpy as np
import math

# print('input >>')
N = int(input())
towns = []
for _ in range(N):
    x, y = map(int,(input().split()))
    towns.append(np.array([x,y]))

sum = 0
perms = itertools.permutations(range(N), N)

distances = [[0] * N for _ in range(N)]

for i in range(N):
    for j in range(N):
        distances[i][j] = np.linalg.norm(towns[i]-towns[j])

sum = 0
for p in perms:
    distance = 0
    for i in range(N-1):
        distance += distances[p[i]][p[i + 1]]
    sum += distance

# print('----------output----------')
print(sum / math.factorial(N))

Measured memory_bytes: 12460
def main():
    h, w, m, *BOM = map(int, open(0).read().split())
    row = [0] * h
    col = [0] * w
    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        row[i] += 1
        col[j] += 1

    p, q = max(row), max(col)
    rr = sum(1 for i in range(h) if row[i] == p)
    rl = sum(1 for i in range(w) if col[i] == q)

    cnd = rr * rl

    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        if (row[i], col[j]) == (p, q):
            cnd -= 1

    if cnd > 0:
        ans = p + q
    else:
        ans = p + q - 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 78084
#include <cstdio>
static const int MAXN = 200003;

int n, m;
bool to1[MAXN] = { false }, ton[MAXN] = { false };

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0, u, v; i < m; ++i) {
        scanf("%d%d", &u, &v); --u, --v;
        if (u == 0) to1[v] = true;
        else if (v == n - 1) ton[u] = true;
    }

    for (int i = 0; i < n; ++i)
        if (to1[i] && ton[i]) { puts("POSSIBLE"); return 0; }

    puts("IMPOSSIBLE"); return 0;
}


Measured memory_bytes: 512
# UnionFind
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(1000000)
class UnionFind:
  def __init__(self, n):
    self.n = [-1]*n
    self.r = [0]*n
    self.siz = n

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

  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.r[x] > self.r[y]:
      self.n[x] += self.n[y]
      self.n[y] = x
    else:
      self.n[y] += self.n[x]
      self.n[x] = y
      if self.r[x] == self.r[y]:
        self.r[y] += 1
    self.siz -= 1

  def root_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

  def count(self, x):
    return -self.n[self.find_root(x)]

  def size(self):
    return self.siz

n,q=map(int,input().split())
uf=UnionFind(n)
for _ in range(q):
  t,u,v=map(int,input().split())
  if t==0:
    uf.unite(u,v)
  else:
    print(uf.root_same(u,v)+0)

Measured memory_bytes: 13296
//
// Created on 2020/06/23.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    //n個の要素のbit全探索する
    ll ans = LINF;
    for (int bit = 0; bit < (1<<n); ++bit) {
        int max_high = 0;
        int can_see = 0;
        ll cost = 0;
        auto a_c = a;
        for (int i = 0; i < n; ++i) {
            if(bit & (1<<i)){
                //i個目の要素にフラグが立っていた時の処理
                if(max_high >= a_c[i]){
                    cost += max_high - a_c[i] + 1;
                    a_c[i] = max_high + 1;
                }
            }
            if(max_high < a_c[i]){
                max_high = max(max_high,a_c[i]);
                can_see ++;
            }
        }
        if(can_see >= k){
            ans = min(ans,cost);
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3512
N, M=map(int, input().split())
KA=[list(map(int,input().split())) for _ in range(N)]

tmp=[0]*(M+1)
for i in range(N):
	for j in range(1,KA[i][0]+1):
		tmp[KA[i][j]]+=1
# print(tmp)
ans=0
for i in range(M+1):
	if tmp[i]==N:
		ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N, X, Y;
    cin >> N >> X >> Y;
    X--; Y--;
    
    vector<long long> ans(N, 0);

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int k = min(
                abs(j - i),
                min(
                    abs(i - X) + 1 + abs(j - Y),
                    abs(i - Y) + 1 + abs(X - j)
                )
            );
            ans[k]++;
        }
    }

    for (int k = 1; k < N; k++) cout << ans[k] << endl;

    
    return 0;
}

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

constexpr int MAX_N = 1e6;

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

vector<int> init() {
	vector<int> num;
	int sum = 0;
	for(int i = 1;; ++i) {
		sum += i;
		if(sum > MAX_N) break;
		num.emplace_back(sum);
	}

	partial_sum(num.begin(), num.end(), num.begin());
	return num;
}

int main() {
	const auto num = init();

	vector<int> dp(MAX_N + 1, INT_MAX);
	vector<int> odd_dp(MAX_N + 1, INT_MAX);
	dp[0] = odd_dp[0] = 0;

	for(unsigned i = 0; i < num.size(); ++i) {
		const int &value = num[i];

		for(int j = 0; j + value <= MAX_N; ++j) {
			chmin(dp[j + value], dp[j] + 1);
		}

		if(value & 1) {
			for(int j = 0; j + value <= MAX_N; ++j) {
				chmin(odd_dp[j + value], odd_dp[j] + 1);
			}
		}
	}

	for(int n; cin >> n && n;) {
		cout << dp[n] << " " << odd_dp[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 8784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    int in[n] = {};
    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        in[y]++;
    }

    int dist[n] = {};
    int mx = -1;
    bool visited[n] = {};
    queue<int> que;
    rep(i, 0, n) {
        if (in[i] == 0) que.push(i);
    }
    while (!que.empty()) {
        int now = que.front();
        que.pop();
        for (int next : g[now]) {
            in[next]--;
            if (in[next] == 0) {
                que.push(next);
                visited[next] = true;
            }
            dist[next] = max(dist[next], dist[now] + 1);
            mx = max(mx, dist[next]);
        }
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 6656
while True:
    n = int(input())
    if n == 0:
        break
    Run = []
    for i in range(n):
        num,m_1,s_1,m_2,s_2,m_3,s_3,m_4,s_4 = map(int,input().split())
        Run.append([(m_1 + m_2 + m_3 + m_4)*60 +s_1 +s_2+s_3+s_4,num])
    Run = sorted(Run)
    print(Run[0][1])
    print(Run[1][1])
    print(Run[len(Run) - 2][1])

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

typedef long long ll;

const ll Inf = 9000000000000000000ll;
const int Maxn = 505;
const int Maxc = 50;

int n, c;
int D[Maxc][Maxc];
int C[Maxn][Maxn];
ll cost[3][Maxc];
ll res = Inf;

int main()
{
	scanf("%d %d", &n, &c);
	for (int i = 1; i <= c; i++)
		for (int j = 1; j <= c; j++)
			scanf("%d", &D[i][j]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			scanf("%d", &C[i][j]);
	for (int i = 0; i < 3; i++)
		for (int j = 1; j <= c; j++) {
			cost[i][j] = 0;
			for (int r = 1; r <= n; r++)
				for (int r2 = 1; r2 <= n; r2++) if ((r + r2) % 3 == i)
					cost[i][j] += D[C[r][r2]][j];
		}
	for (int c1 = 1; c1 <= c; c1++)
		for (int c2 = 1; c2 <= c; c2++) if (c1 != c2)
			for (int c3 = 1; c3 <= c; c3++) if (c1 != c3 && c2 != c3)
				res = min(res, cost[0][c1] + cost[1][c2] + cost[2][c3]);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

#define bit(b, i) (((b) >> (i)) & 1)

int main() {
	auto f = [](LL & a, LL & b, const LL c) {
		dec(i, 41) {
			if(bit(a ^ b ^ c, i) != 0) {
				LL m = (1LL << i) - 1;
				LL A = (a & m) + 1;
				LL B = m - (b & m) + 1;
				if(A == B) { a = 0; return; }
				LL mi = min(A, B);
				a -= mi;
				b += mi;
				break;
			}
		}
	};
	
	IN(int, n);
	IN(LL, a, b);
	LL c = 0;
	inc(i, n - 2) { IN(LL, x); c ^= x; }
	
	LL a0 = a;
	while(true) {
		f(a, b, c);
		if(a <= 0) { OUT(-1); break; }
		if((a ^ b ^ c) == 0) { OUT(a0 - a); break; }
	}
}


Measured memory_bytes: 3604
main :: IO ()
main = do
    [x1, y1, x2, y2] <- map read . words <$> getLine
    putStrLn $ unwords $ map
        show
        [x2 + y1 - y2, y2 + x2 - x1, y1 - y2 + x1, x2 - x1 + y1]

Measured memory_bytes: 508
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			
			if (H == 0 && W == 0) { break; }
			
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if ( (i==0 || i==H-1) || (j==0 || j==W-1) )
						System.out.print("#");
					else
						System.out.print(".");
					
				}
				System.out.println();
			}
			System.out.println();

		}
		
		sc.close();
	}
}



Measured memory_bytes: 34148
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
//#include <unordered_map> //C++11
using namespace std;

typedef long long ll;

int main() {
	string o, e;
	cin >> o >> e;
	for (int i = 0; i < e.length(); i++) cout << o.at(i) << e.at(i);
	if (o.length() > e.length()) cout << o.back();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,i;
    double sum=0.0;
    scanf("%d",&n);
    int a[1000];
    float f[1000];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        f[i]=(float)a[i];
    }
    for(i=0;i<n;i++){
        sum=sum+(1.0/f[i]);
    }
    sum=1.0/sum;
    printf("%f\n",sum);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(n));
    for(auto &&i : v) for(auto &&j : i) scanf("%d", &j);
    vector<ll> dp(1<<n), dq(1<<n);
    for (int i = 1; i < (1<<n); ++i) {
        for (int j = 0; j < n; ++j) {
            if(i & (1 << j)){
                int a = i ^ (1 << j);
                dp[i] = dp[a];
                for (int k = 0; k < n; ++k) {
                    if(a & (1 << k)){
                        dp[i] += v[j][k];
                    }
                }
                break;
            }
        }
    }
    for (int i = 1; i < (1 << n); ++i) {
        dq[i] = dp[i];
        for (int j = (i-1)&i; j != i; j = (j-1)&i) {
            dq[i] = max(dq[i], dq[i^j]+dp[j]);
        }
    }
    cout << dq.back() << "\n";
    return 0;
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;






void one_case() {
    int n, a, b;
    cin >> n >> a >> b;

    int res = 0;
    for (int i = 1; i <= n; ++i) {
        int s = 0;
        for (auto l : to_string(i)) s += int(l) - 48;
        if (s >= a && s <= b) res += i;
    }
    cout << res << '\n';

}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pint;
typedef map <int,int> mapii;
typedef map <char,int> mapci;
typedef map <string,int> mapsi;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <char> vc;
typedef set <int> si;
typedef set <ll> sll;
typedef set <char> sc;
#define pb(i) push_back(i) ;
#define ms(arr) memset(arr,0,sizeof(arr))
#define deb(x) cout<< #x <<" "<< x<<endl;
#define loop(i,n) for(int i=0;i<n;i++)
#define Loop(i,k,n) for(int i=k;i<=n;i++)
#define testcase int t;cin>>t; while(t--)

int main() {
    ll a,b;
    cin>>a>>b;
    if(a%2!=b%2)
        cout<<"IMPOSSIBLE";
    else
        cout<<(a+b)/2;
}

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

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int N = 1 << 18;
int a[N];

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

	int n; cin >> n;
	int x = 0;
	rep(i, 0, n) {
		cin >> a[i];
		x ^= a[i];
	}
	rep(i, 0, n) cout << (x ^ a[i]) << ' ';
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k,n,i,j;
    cin>>n>>k;
    ll dig=0;
    while(n>0)
    {
        dig++;
        n/=k;
    }
    cout<<dig;


    
    return 0;
    
}
    

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, k;
vector<ll> a, b;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    a.resize(n);
    b.resize(n);
    rep(i, n) cin >> a[i] >> b[i];
    ll ans = 0;
    vector<bool> bitk(31, false);
    rep(i, 31)
    {
        if ((1 << i) & k)
        {
            bitk[i] = true;
        }
    }
    rep(i, n)
    {
        bool check = true;
        rep(j, 31)
        {
            if (a[i] & (1 << j) && !bitk[j])
            {
                check = false;
            }
        }
        if (check)
            ans += b[i];
    }
    rep(i, 31)
    {
        if (!bitk[i])
            continue;
        ll sum = 0;
        rep(j, n)
        {
            if (a[j] & (1 << i))
                continue;
            bool check = true;
            for (int l = i + 1; l < 31; l++)
            {
                if (a[j] & (1 << l) && !bitk[l])
                {
                    check = false;
                }
            }
            if (check)
            {
                sum += b[j];
            }
        }
        chmax(ans, sum);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1792
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; long x; rd(n, x);
  auto a=readln.split.to!(long[]);

  sort(a);
  int num=0;
  foreach(e; a){
    if(x>=e) num++;
    x-=e;
  }
  if(x>0) num--;
  writeln(num);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


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

int main() {
  int N,X=30;
  cin>>N;
  for(int i=0;i<N;i++){
    int A,C=0;
    cin>>A;
   for(int j=0; j<30; j++){
     if(A%2==0){
      C++;A/=2;
   }
   }
   if(C<X)X=C;
  }
  cout<<X<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n, t;
    cin >> n >> t;
    ll min_cost = 10000;
    for(int i = 0; i < n; ++i){
        ll ci, ti;
        cin >> ci >> ti;
        if(ti <= t){
            min_cost = min(ci, min_cost);
        }
    }
    if(min_cost < 10000){
        cout << min_cost << endl;
    }else{
        cout << "TLE" << endl;
    }
    return 0;
}


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

int main() {
  int N, K, result=1, ans=1025;
  cin >> N >> K;
  
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < i; j++) result = result * 2;
    for (int a = 0; a < N-i; a++) result = result + K;
    if (result < ans) ans = result;
    result = 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define N 20
#define M 66666
#define mod 1000000007
#define ll long long
#define db double
#define dbg1(x) cout<<#x<<"="<<x<<" "
#define dbg2(x) cout<<#x<<"="<<x<<"\n"
int n,m,A[N],f[N][M],MaxS,fac[M],inv[M],ans;
int cal(int x) {x-=x<mod?0:mod;return x;}
int C(int x,int y) {return (ll)fac[x]*inv[y]%mod*inv[x-y]%mod;}
int main()
{
	scanf("%d%d",&n,&m),MaxS=(1<<n)-1;
	for(int i=1;i<=m;i++) scanf("%d",&A[i]);
	reverse(A+1,A+1+m);
	fac[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=MaxS;i++) fac[i]=(ll)fac[i-1]*i%mod;
	for(int i=2;i<=MaxS;i++) inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<=MaxS;i++) inv[i]=(ll)inv[i-1]*inv[i]%mod;
	f[0][0]=1;
	for(int i=0,cnt;i<m;i++)
		for(int j=0;j<=MaxS;j++)
		{
			if(!f[i][j]) continue;
			f[i+1][j]=cal(f[i+1][j]+f[i][j]);
			cnt=MaxS+1-A[i+1];
			for(int k=1;k<=n;k++) if(j>>k-1&1) cnt-=1<<k-1;
			for(int k=1;k<=n;k++)
				if(!(j>>k-1&1)&&cnt+1>=1<<k-1)
					f[i+1][j|(1<<k-1)]=cal(f[i+1][j|(1<<k-1)]+(ll)f[i][j]*C(cnt,(1<<k-1)-1)%mod);
		}
	/*for(int i=1;i<=m;i++)
		for(int j=0;j<=MaxS;j++)
			if(f[i][j]) dbg1(i),dbg1(j),dbg2(f[i][j]);*/
	for(int i=0,res,cnt,tot;i<=MaxS;i++)
	{
		cnt=MaxS,tot=0,res=f[m][i];
		for(int j=1;j<=n;j++) if(i>>j-1&1) cnt-=1<<j-1,tot++;
		for(int j=1;j<=n;j++)
			if(!(i>>j-1&1)) res=(ll)res*C(cnt,1<<j-1)%mod,cnt-=1<<j-1;
		ans=cal(ans+(tot&1?mod-res:res));
	}
	for(int i=0;i<n;i++) ans=(ll)ans*fac[1<<i]%mod;
	printf("%d\n",(ll)ans*(MaxS+1)%mod); 
	return 0;
}

Measured memory_bytes: 4224
inp=input
li=list
iinp=lambda : int(inp())
ent=lambda : map(int,inp().split())
lient=lambda : [int(i) for i in inp().split()]
li0= lambda x: [0 for i in range(x)]
livalor=lambda valor,x: [valor for i in range(x)]
stent=lambda : [i for i in inp()]
filldp=lambda valor,x,y: [[valor for i in range(y)] for i in range(x)]

s=inp()
t=inp()
if t[:-1]==s:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9088
#include <iostream>
using namespace std;
int val[]={1,2,4,8};
int cost[4];
long long N;
int main()
{
    for(int i=0;i<4;i++)cin>>cost[i];
    cin>>N;N*=4;
    for(int i=0;i<4;i++)
    {
        for(int j=i+1;j<4;j++)
        {
            cost[j]=min(0LL+cost[j],1LL*cost[i]*val[j]/val[i]);
        }
    }
    long long rez=0;
    for(int i=3;i>=0;i--)
    {
        rez+=(N/val[i])*cost[i];
        N%=val[i];
    }
    cout<<rez;
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    int N, K;
    int R, S, P;
    
    string T;

    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    ll L = T.length();
    vector<bool> C(L, true);
    ll ans = 0;
    for(int i=0; i< T.length(); i++){
        if(i < K){
            if(T[i] == 'r') ans += P;
            if(T[i] == 's') ans += R;
            if(T[i] == 'p') ans += S;
            C[i] = false;
        }
        else{
            if(C[i-K] || (T[i] != T[i-K])){
                if(T[i] == 'r') ans += P;
                if(T[i] == 's') ans += R;
                if(T[i] == 'p') ans += S;
                C[i] = false;
            }
        }
        // cout << ans << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int(i)=int (a);i<=int (b);i++)
#define ff(i,a,b) for(int(i)=int (a);i<int (b);i++)
#define F(i,a,b) for(int(i)=int (a);i>=int (b);i--)
#define foreach(i,x) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vt vector
#define ll long long
#define lower(p,x) lower_bound(all(p),x)
#define upper(p,x) upper_bound(all(p),x)
#define ms(a,x) memset(a,x,sizeof a)
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const double pi=acos(-1.0);//NOTE:PI
const double eps=1e-5;
const int INF=1e9,mod=1e9+7,N=1e6+1;
int a[N];
ll ans=0;
int n,x;
int main(){
	cin>>n>>x;
	f(i,1,n) cin>>a[i];
	if(a[1]>x){
		ans+=a[1]-x;
		a[1]=x;
	}
	f(i,2,n){
		if(a[i]+a[i-1]>x){
			ll tmp=a[i]+a[i-1]-x;
			ans+=tmp;
			a[i]-=tmp;
		}
	}
	cout<<ans;
}	
	
	
	


Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string S;
  cin >> S;
  long long s = 0;
  for (int i = 0; i <= 3; i++) {
    s *= 10;
    s += (int)S[i] - (int)'0';
  }
  for (int i = 5; i <= 6; i++) {
    s *= 10;
    s += (int)S[i] - (int)'0';
  }
  for (int i = 8; i <= 9; i++) {
    s *= 10;
    s += (int)S[i] - (int)'0';
  }
  if (s <= 20190430) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  int H[N];
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  int h=0;
  int ans=0;
  for(int i=0;i<N;i++){
    if(h <= H[i]){
      h = H[i];
      ans++;
    }
  }
  cout << ans  << endl;
}

Measured memory_bytes: 256