akhauriyash/Code-Regression huggingface dataset:
def vacation(costs):
    total = [0, 0, 0]
    next_total = [0, 0, 0]

    i, j, k = 0, 1, 2
    for c in costs:
        for _ in range(3):
            next_total[i] = c[i] + max(total[j], total[k])
            i, j, k = j, k, i
        total, next_total = next_total, total
    return max(total)


def main():
    n = int(input())

    costs = [None] * n
    for idx in range(n):
        costs[idx] = [int(x) for x in input().split()]

    return vacation(costs)

print(main())


Measured memory_bytes: 55512
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
vector<pair<ll,int>>vec;
int sz[100005];
vector<int>edge[100005];
ll dist[100005];
void dfs(int v,int u,int d){
	dist[v] = d;
	rep(i,edge[v].size()){
		if(edge[v][i] == u) continue;
		dfs(edge[v][i],v,d+1);
	}
}
ll O;
int main(){
	scanf("%d",&n);
	repn(i,n){
		ll a; scanf("%lld",&a) ; vec.pb(mp(-a,i)); if(i == 1) O = a;
	}
	sort(vec.begin(),vec.end());
	
	repn(i,n) sz[i] = 1;
	
	for(int i=0;i<n-1;i++){
		ll a = vec[i].fi;
		int v = vec[i].sc;
		
		ll need = -a - (n-2*sz[v]);
		int aa = POSL(vec,mp(-need,-1));
		if(aa < vec.size() && -vec[aa].fi != need){
			puts("-1"); return 0;
		}
		//cout << v << " " << vec[aa].sc << endl;
		edge[vec[aa].sc].pb(v);
		edge[v].pb(vec[aa].sc);
		sz[vec[aa].sc] += sz[v];
	}
	fill(dist,dist+100005,1e18);
	dfs(1,-1,0);
	
	repn(i,n){
		O -= dist[i];
	}
	
	if(O){
		puts("-1"); return 0;
	}
	
	repn(i,n){
		rep(j,edge[i].size()){
			int to = edge[i][j];
			if(i < to) printf("%d %d\n",i,to);
		}
	}
	return 0;
}

Measured memory_bytes: 12784
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();		
		String s = r.str();
		for(int i = s.length()-2; i>=0; i--)
		{
			if((i%2)==0) continue;
			if(s.substring(0, i/2).equals(s.substring(i/2+1, i))) {
				print(i+1);
				return;
			}
		}
		print(-1);
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}
	
	public static String al(String s) {
		return s + "\n";
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}

Measured memory_bytes: 21332
#include <stdio.h>
#include <stdlib.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define MAX 100001
typedef struct data{
    int n,m;
}Data;
Data e[MAX],o[MAX];
int cmp(const void *a,const void *b){
    return ((Data *)b)->m-((Data *)a)->m;
}
int main(){
    int n,i,buf,ans;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&buf);
        if(i%2==0){
            e[buf-1].m++;
            e[buf-1].n=buf;
        }
        else{
            o[buf-1].m++;
            o[buf-1].n=buf;
        }        
    }
    qsort(e,MAX,sizeof(Data),cmp);
    qsort(o,MAX,sizeof(Data),cmp);
    if(e[0].n==o[0].n)ans=min(n-e[0].m-o[1].m,n-e[1].m-o[0].m);
    else ans=(n-e[0].m-o[0].m);
    printf("%d",ans);
}

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

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

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

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

void solve(long long H, long long W, std::vector<std::string> s)
{
    string ans = YES;
    rep(i, H)
    {
        rep(j, W)
        {
            if (s[i][j] == '#')
            {

                int count = 0;
                if (0 <= j - 1)
                {
                    if (s[i][j - 1] == '#')
                    {
                        count++;
                    }
                }
                if (W > j + 1)
                {
                    if (s[i][j + 1] == '#')
                    {
                        count++;
                    }
                }
                if (0 <= i - 1)
                {
                    if (s[i - 1][j] == '#')
                    {
                        count++;
                    }
                }
                if (H > i + 1)
                {
                    if (s[i + 1][j] == '#')
                    {
                        count++;
                    }
                }
                if (count == 0)
                {
                    ans = NO;
                }
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    long long H;
    scanf("%lld", &H);
    long long W;
    scanf("%lld", &W);
    std::vector<std::string> s(H);
    for (int i = 0; i < H; i++)
    {
        std::cin >> s[i];
    }
    solve(H, W, std::move(s));
    return 0;
}


Measured memory_bytes: 256
nm=list(map(int,input().split()))
p=[]
for i in range(nm[0]):
    p.append([])
for i in range(nm[1]):
    py=list(map(int,input().split()))
    p[py[0]-1].append([i,py[1]])
#pの構造：p[i]=i県の市のリスト/p[i][j]=j番目に入力された市の[全体での番号i、成立年]
#あとで各iについてp[i]を成立年で昇順ソートする
from operator import itemgetter
for i in range(nm[0]):
    p[i].sort(key=itemgetter(1))
    #全ての市の情報リストのインデックス2に県番号を追加(ID構築用)
    for j in range(len(p[i])):
        p[i][j][-1]=j+1
        p[i][j].append(i+1)
#市iの情報は[i,Pi内の成立順位,Pi]
#pの各要素を連結し、最小単位が市の情報リストであるようなリストを新しく作る
c=p[0]
for i in range(1,nm[0]):
    c+=p[i]
c.sort()
for i in range(nm[1]):
    prefecture=str(c[i][2])
    rank=str(c[i][1])
    padding_p="0"*(6-len(prefecture))
    padding_r="0"*(6-len(rank))
    print(padding_p+prefecture+padding_r+rank)


Measured memory_bytes: 36304
/*....Bismillahir Rahmanir Rahim....*/
/**
      Author  :  Md. Sajjat Hosen
      Created :  Friday, 25 April, 2020
**/
/*....! TRY ONCE MORE !....*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long               ll;
typedef long double             ld;
typedef unsigned long long      ull;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

inline int Int() { int x; scanf("%d", &x); return x; }
inline ll Long() { ll x; scanf("%lld", &x); return x; }
inline float Float() { float x; scanf("%f", &x); return x; }
inline double Double() {double x; scanf("%lf", &x); return x; }

//    Moves : L, U, R, D, LU, RU, RD, LD.
int dx[8] = { 0, -1, 0, 1, -1, -1, 1, 1 };
int dy[8] = { -1, 0, 1, 0, -1, 1, 1, -1 };

const int N          = (int)2e5 + 5;
const int maxN       = (int)1e6 + 6;
const ll  Mod        = (ll)1e9 + 7;
const int inf        = (int)2e9;
const ll  Inf        = (ll)1e18;

#define     debug(x)    cerr << #x << " = " << x << '\n';
#define     Int         Int()
#define     Long        Long()
#define     Float       Float()
#define     Double      Double()
#define     all(x)      x.begin(), x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mp          make_pair
#define     TN          typename
#define     pie         acos(-1.0)
#define     nl          '\n'
#define     Fast_Read   ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

template <TN T> T gcd(T a, T b) { return !b ? a : gcd(b, a % b); }
template <TN T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }

/*...... ! Code start from here ! ......*/
map<int, int> m;
set<int> s;
int main() {
    Fast_Read
    //freopen("input.txt", "r", stdin);
    int test = 1, tc = 0;
    while (test--) {
        int n, x;
        ll ans = 0;
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> x;
            m[x]++;
            s.insert(x);
        }
        for (auto i : s) {
            if (i < m[i]) {
                ans += abs(m[i] - i);
            } else if (i > m[i]) {
                ans += m[i];
            }
        }
        cout << ans << nl;
    }
    return 0;
}

/*................END.................*/

Measured memory_bytes: 9344
#include <map>
#include <queue>
#include <iostream>
typedef unsigned long long ull;
using namespace std;
struct state { ull x; int zero, pre, dist, remain; };
bool operator<(const state& s1, const state& s2) { return s1.dist + s1.remain > s2.dist + s2.remain; }
int a, dist[16][16], goals[16], goals2[16]; ull s, goal = 1147797409030816545;
int solve() {
	if (s == goal) return 0;
	int zz = -1;
	for (int i = 0; i < 16; i++) {
		if (!((s >> (i * 4)) & 15)) zz = i;
	}
	int rr = 0;
	for (int i = 0; i < 16; i++) {
		int ww = ((s >> (i * 4)) & 15);
		if (!ww) continue;
		for (int j = 0; j < 16; j++) {
			if (ww == goals[j]) {
				rr += dist[i][j];
			}
		}
	}
	for (int level = rr; ; level++) {
		queue<state> que;
		que.push(state{ s, zz, -99, 0, rr });
		while (!que.empty()) {
			state a = que.front(); que.pop();
			ull v = a.x; int z = a.zero;
			int dir[4] = { 1, 0, -1, 0 };
			for (int i = 0; i < 4; i++) {
				if (abs(i - a.pre) == 2) continue;
				int dx = dir[i], dy = dir[i ^ 1];
				int e = z + dy * 4 + dx;
				int g = ((v >> (e << 2)) & 15);
				if (0 <= e && e < 16 && (e & 3) - (z & 3) == dx) {
					ull w = v;
					w -= ((1ULL * g) << (e << 2));
					w += ((1ULL * g) << (z << 2));
					int xx = a.remain;
					xx -= dist[e][goals2[g]];
					xx += dist[z][goals2[g]];
					if (w == goal) return a.dist + 1;
					if (a.dist + xx + 1 <= level) que.push(state{ w, e, i, a.dist + 1, xx });
				}
			}
		}
	}
	return -1;
}
int main() {
	for (int i = 0; i < 16; i++) {
		for (int j = 0; j < 16; j++) {
			dist[i][j] = abs((i >> 2) - (j >> 2)) + abs((i & 3) - (j & 3));
		}
	}
	for (int i = 0; i < 15; i++) goals[i] = i + 1; goals[15] = 0;
	for (int i = 0; i < 16; i++) goals2[goals[i]] = i;
	for (int i = 0; i < 16; i++) {
		cin >> a;
		s += ((1ULL * a) << (i * 4));
	}
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 12248
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	llint n,i,q,k;cin>>n;
	vector<llint> dis(n,big);
	vector<vector<pair<llint,llint>>> road(n);
	for(i=0;i<n-1;i++){
		int a,b,c;
		cin>>a>>b>>c;a--;b--;
		road[a].pub(mp(c,b));
		road[b].pub(mp(c,a));
	}
	cin>>q>>k;k--;
	priority_queue<pair<llint,llint>,vector<pair<llint,llint>>,greater<pair<llint,llint>> >que;
	que.push(mp((llint)0,k));
	while(!que.empty()){
		llint now=que.top().fir;
		llint town=que.top().sec;
		que.pop();
		if(now>dis[town]){continue;}
		for(auto it=road[town].begin();it!=road[town].end();it++){
			if(dis[it->sec]<=(now+it->fir)){continue;}
			dis[it->sec]=(now+it->fir);
			que.push(mp(now+it->fir,it->sec));
		}
	}
	for(i=0;i<q;i++){
		llint x,y;cin>>x>>y;x--;y--;
		cout<<dis[x]+dis[y]<<endl;
	}
	return 0;
}

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

int main(void){
  int q;
  cin>>q;
  vector<int>v;
  while(q--){
    int t;
    cin>>t;
    if(t==0){
      int x;
      cin>>x;
      v.push_back(x);
    }else if(t==1){
      int p;
      cin>>p;
      cout<<v[p]<<endl;
    }else{
      v.pop_back();
    }
  }
  return 0;
}



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

using namespace std;
int main () {
    int f = 2,s = 1;
    int x; 
    for ( int i = 0 ; i < 3 ; i++ ) {
        cin >> x;
        if ( x == 5 ) f--;
        if ( x == 7 ) s--;
    }
    if ( !f && !s ) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
	int n, W;
	scanf("%d %d", &n, &W);
	vector<ll> dp(W + 1, 0);
	for (int k = 0; k < n; k++) {
		int w, val;
		scanf("%d%d", &w, &val);
		for (int x = W - w; x >= 0; x--) {
			dp[x + w] = max(dp[x + w], dp[x] + val);
		}
	}
	ll res = 0;
	for (int i = 0; i <= W; i++) {
		res = max(res, dp[i]);
	}
	printf("%lld\n", res);
}


Measured memory_bytes: 3664
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

long long berger[51];

long long niku[51];
long long count(int n) {
	if (berger[n] != 0)return berger[n];
	
	return berger[n] = count(n - 1) * 2 + 3;
}
long long countniku(int n) {
	if (niku[n] != 0)return niku[n];
	return niku[n] = countniku(n - 1) * 2 + 1;
}



int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}


int main() {
	long long n, x;
	cin >> n >> x;
	berger[0] = 1;
	niku[0] = 1;
	long long total = 0;
	for (int i = n; i > 0; i--) {
		if (x >= count(i - 1) + 2) {
			x -= count(i - 1) + 2;
			total += countniku(i- 1) + 1;
		}
		else {
			x -= 1;
		}
	}

	if (x > 0)total++;
	cout << total;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [6**i for i in range(7)]
q = [9**j for j in range(6)]
m = {}

def b(n):
  if n < 6:
    return n
  elif n in m:
    return m[n]
  else:
    m_s = max(i for i in s if i<=n)
    m_q = max(j for j in q if j<=n)
    ms = n - m_s
    mq = n - m_q
    m[n] = min(b(ms)+1, b(mq)+1)
    return m[n]

print(b(n))

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

using namespace std;

using Int = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; ++i) cin >> H[i];
  int step = 0;
  int prev_H = H[0];
  int ans = 0;
  for (int i = 1; i < N; ++i) {
    if (H[i] <= prev_H) step++;
    else {
      ans = max(ans, step);
      step = 0;
    }
    prev_H = H[i];
  }
  ans = max(ans, step);
  cout << ans << endl;
}

Measured memory_bytes: 768
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

#define sz 500

int mem[sz];
int cnt[sz];

main(){
    int k;cin>>k;mem[0]=1;
    for(int i=1;i<sz;i++){
        mem[i]=mem[i-1]*(i+7)/i;
        
    }
    for(int i=sz-1;i>=0;i--){
        cnt[i]=k/mem[i];k%=mem[i];
    }
    rep(i,sz){
        cout<<"FESTIVA";rep(j,cnt[i])cout<<"L";
    }
    cout<<endl;
}


Measured memory_bytes: 256
n = gets.to_i

def read_table()
	table = {}
	s = gets.strip.split(//).each{|c|
		if table[c]
			table[c] += 1
		else
			table[c] = 1
		end
	}
	table
end

table = read_table()
(n - 1).times{
	table2 = read_table()
	
	table.keys.each{|c|
		if count = table2[c]
			table[c] = [table[c], count].min
		else
			table.delete(c)
		end
	}
}

puts table.to_a.sort.collect{|c, count| c * count}.join




Measured memory_bytes: 1916
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
  ll x;
  cin>>x;
  ll yo=x%10;
  if(yo==2 || yo==4 || yo==5 || yo==7 || yo==9)cout<<"hon";
  else if(yo==0 || yo==1 || yo==6 || yo==8)cout<<"pon";
  else cout<<"bon";
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 3628
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [d, n] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const divideCount = x => {
  let c = 0
  while (x % 100 === 0) {
    c++

    x /= 100

    if (x < 100) {
      return c
    }
  }
  return c
}

const ans = _ => {
  let count = 0
  let num = 1

  while (1) {
    switch (d) {
      case 0:
        if (divideCount(num) === 0) count++
        break
      case 1:
        if (divideCount(num) === 1) count++
        break
      case 2:
        if (divideCount(num) === 2) count++
        break
    }

    if (count === n) {
      return num
    }

    num++
  }
}

console.log(ans())


Measured memory_bytes: 7500
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y; cin >> x >> y;
    ll ans = 0;
    if (x == 1 && y == 1) ans = 400000;
    if (x == 1) ans += 300000;
    else if (x == 2) ans += 200000;
    else if (x == 3) ans += 100000;

    if (y == 1) ans += 300000;
    else if (y == 2) ans += 200000;
    else if (y == 3) ans += 100000;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
// const ll MOD = 1e9 + 7 ;
const ll MOD = 998244353 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , s ;
vector<int> v ; 
map<int,int> mp ;
int dp[3003][3003] ; 
int dfs(int x, int cur){
    if ( x == n ){
        if ( cur == 0 ) {
            return 1 ;
        }
        return 0 ;
    }
    if ( dp[x][cur] != -1 ) return dp[x][cur] ;
    int ans = 2 * dfs(x + 1, cur) ;
    ans %= MOD ;
    if ( v[x] <= cur ){
        ans += dfs(x + 1, cur - v[x]) ;
        ans %= MOD ;
    }
    return dp[x][cur] = ans % MOD ; 
}
signed main(){
    fastio
    memset(dp, -1, sizeof dp) ;
    cin >> n >> s ;
    v = vector<int>(n) ;
    for(int i = 0; i < n; i++){
        cin >> v[i] ;
    }
    int ans = dfs(0, s) ;
    cout << ans << endl ;
    return 0; 
}

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

 
int main(){
    long long K;
    cin >> K;
    long long count = 1;
    queue<long long> que;
    for(int i=1;i<=9;i++){
        que.push(i);
    }
    while(count <= K){
        long long k = que.front();
        que.pop();
        //cout << k << endl;
        if(count == K){
            cout << k << endl;
            break;
        }
        if(k % 10 != 0){
            que.push(10 * k + (k % 10 - 1));
        }
        que.push(10 * k + k % 10);
        if(k % 10 != 9){
            que.push(10 * k + (k % 10 + 1));
        }
        count++;
    }


    return 0;
}

Measured memory_bytes: 1792
import sys, math

array = []
for line in sys.stdin:
    array.append(map(int, line.split(' ')))

for a, b, c, d, e, f in array:
    determinant = a * e - b * d
    if determinant == 0:
        print('NO ANSWER')
    x = (c * e - b * f) / determinant
    y = (a * f - c * d) / determinant
    x = math.floor(x * 1000) / 1000
    y = math.floor(y * 1000) / 1000

    print('{0:.3f} {1:.3f}'.format(x, y))


Measured memory_bytes: 5680
#include <iostream>
using namespace std;
int main()
{
    int n;
    string s;
    int count[4] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s == "AC") count[0] += 1;
        if (s == "WA") count[1] += 1;
        if (s == "TLE")count[2] += 1;
        if (s == "RE") count[3] += 1;
    }
    cout << "AC x " << count[0] << endl
         << "WA x " << count[1] << endl
         << "TLE x "<< count[2] << endl
         << "RE x " << count[3] << endl;
    return 0;
}

Measured memory_bytes: 3628
// DAG
#include<iostream>
#include<map>
#include<stack>
#include<vector>
#include<set>
#include<queue>
using namespace std;

int main(){
    int n, m;
    scanf("%d %d", &n, &m);

    vector<int> edge[n+1];
    vector<int> indeg(n+1, 0);

    int a, b;
    for(int i = 0; i < n+m-1; i++){
        scanf("%d %d", &a, &b);
        indeg[b]++;
        edge[a].push_back(b);
    }

    vector<int> ans(n+1, 0);
    queue<int> q;
    for(int i = 1; i <= n; i++){
        if(indeg[i] == 0)   q.push({i});
    }

    while(!q.empty()){
        int now = q.front();    q.pop();
        for(int next : edge[now]){
            indeg[next]--;
            if(indeg[next] == 0){
                ans[next] = now;
                q.push(next);
            }
        }
    }
    
    for(int i = 1; i <= n; i++) printf("%d\n", ans[i]);

    return 0;
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  int ans = 0;
  if(x == 3){
    ans += 100000;
  }else if(x == 2){
    ans += 200000;
  }else if(x == 1){
    ans += 300000;
  }
  if(y == 3){
    ans += 100000;
  }else if(y == 2){
    ans += 200000;
  }else if(y == 1){
    ans += 300000;
  }
  if(x==1 && y==1){
    ans += 400000;
  }
  cout << ans;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

ll mpow(ll n, ll e, ll mod) {
	ll r = 1;
	while (e) {
		if (e & 1)
			r = r * n % mod;
		e /= 2;
		n = n * n % mod;
	}
	return r;
}
ll popc(ll n) {
	ll cnt = 0;
	while (n) {
		cnt += n & 1;
		n >>= 1;
	}
	return cnt;
}
ll f(ll n) {
	if (n)
		return f(n % popc(n)) + 1;
	return 0;
}
int n;
char s[210000];
int main() {
	scanf("%d", &n);
	scanf("%s", s);
	int popc = 0;
	for (int i = 0; s[i]; i++)
		if (s[i] - '0')
			popc++;
	ll p = 0, exp = 1;
	for (int i = 1; i <= n; i++) {
		p += exp * (s[n - i] - '0');
		p %= (popc + 1);
		exp = exp * 2 % (popc + 1);
	}
	ll q = 0;
	exp = 1;
	for (int i = 1; i <= n && (popc - 1) > 0; i++) {
		q += exp * (s[n - i] - '0');
		q %= (popc - 1);
		exp = exp * 2 % (popc - 1);
	}

	for (int i = 1; i <= n; i++) {
		if (s[i - 1] - '0') {
			if (popc == 1) {
				printf("0\n");
				continue;
			}
			ll r = q - mpow(2, n - i, popc - 1);
			r = ((r % (popc - 1)) + (popc - 1)) % (popc - 1);
			printf("%lld\n", f(r) + 1);
		}
		else {
			ll r = p + mpow(2, n - i, popc + 1);
			r = r % (popc + 1);
			printf("%lld\n", f(r) + 1);
		}
	}
}

Measured memory_bytes: 1928
#include <cstdio>
#include <vector>
#include <map>

using std::vector;
using std::map;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n), b(n + 1);
  map<int, int> h;
  for (auto &x : a) scanf("%d", &x);
  for (int i = 0; i < n; i++) b[i + 1] = (b[i] + a[i]) % m;
  auto res = 0L;
  for (int i = 0; i <= n; i++) {
    if (h.count(b[i])) res += h[b[i]];
    h[b[i]]++;
  }
  printf("%ld\n", res);
}

Measured memory_bytes: 3968
n, l = map(int, input().split())
b = [0] * n
for i in range(n):
    b[i] = l + i
# b.sort()
s = sum(b)
k1 = 10000000000
k2 = 0
for i in range(n):
    s1 = s - b[i]
    # print(s1, s-s1, k1)
    if abs(abs(s)-abs(s1)) < k1:
        k1 = abs(abs(s)-abs(s1))
        k2 = s1


print(k2)

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

int main() {
 long long a,b,c,k,d;
 cin>>a>>b>>c>>k;
 if(k<a) cout<<k;
 else{
     if(a+b>=k) cout<<a;
     else{
         d=k-(a+b);
         cout<<a-d;
     }
 }

 
 
 return  0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define Max(x, y)(max(decltype(x)(0), max((x), (y))))
#define Min(x, y)(max(decltype(x)(0), min((x), (y))))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool _max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool _min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    Out(n / 3);

    return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>):Unit {
    val charToPoint = mapOf(Pair("A", Point(0, 0)), Pair("B", Point(1, 0)), Pair("C", Point(2, 0)),
            Pair("D", Point(0, 1)), Pair("E", Point(1, 1)), Pair("F", Point(2, 1)),
            Pair("G", Point(0, 2)), Pair("H", Point(1, 2)), Pair("I", Point(2, 2))
            )
    val points = (0 until 3).flatMap{y -> (0 until 3).map{Point(it, y)}}
    while(true){
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        val roomState = Array(3){Array(3){true}}
        val (s, t, b) = readLine()!!.trim().split(' ')
        val start = charToPoint[s]!!
        val buttery = charToPoint[t]!!
        roomState[charToPoint[b]!!.y][charToPoint[b]!!.x] = false
        val matrix = Array(9){Array(9){.0}}
        points.forEachIndexed { index, point ->
            point.neighbors().forEach {
                if (it.x in 0 until 3 && it.y in 0 until 3 && roomState[it.y][it.x]){
                    matrix[index][it.x + it.y * 3] += 0.25
                }else{
                    matrix[index][point.x + point.y * 3] += 0.25
                }
            }
        }
        val res = exp(matrix, n)
        println(res[buttery.x + buttery.y * 3][start.x + start.y * 3])
    }
}
operator fun Array<Array<Double>>.times(that:Array<Array<Double>>):Array<Array<Double>> {
    return this.map{line ->
        that.first().indices.map{column ->
            line.zip(that.map{it[column]}).sumByDouble{(a, b) -> a * b}
        }.toTypedArray()
    }.toTypedArray()
}
fun exp(base:Array<Array<Double>>, e:Int):Array<Array<Double>> {
    return when(e){
        0 -> Array(base.size){y -> Array(base.size){x -> if (x == y) 1.0 else .0}}
        1 -> base
        else -> exp(base, e / 2).let{if (e % 2 == 1) base * it * it else it * it}
    }
}
data class Point(val x:Int, val y:Int){
    operator fun plus(that:Point):Point = Point(x + that.x, y + that.y)
    fun neighbors():Iterable<Point> = listOf(Point(1, 0), Point(-1, 0), Point(0, 1), Point(0, -1)).map{this + it}
}


Measured memory_bytes: 46948
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma region header
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
#pragma endregion
#pragma endregion



int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	lint n; cin >> n;
	cout << n * (n - 1) / 2 << endl;

	return 0;
}

Measured memory_bytes: 3460
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char a[5000];

bool isNum(char ch)
{
    if(ch>='0'&&ch<='9')
        return true;
    return false;
}

int main()
{
    int A,B;
    bool flag;
    while(scanf("%d%d",&A,&B)==2)
    {
        flag=true;
        scanf("%s",a);
        if(strlen(a)!=A+B+1)
        {
            flag=false;
        }
        if(flag)
        {
            for(int i = 0; i < A ; i++)
            {
                if(isNum(a[i])==false)
                {
                    flag=false;
                    break;
                }
            }
            if(a[A]!='-')
            {
                flag=false;
            }
            for(int i = A+1; i < A+B+1 ; i++)
            {
                if(isNum(a[i])==false)
                {
                    flag=false;
                    break;
                }
            }
        }

        printf("%s\n",flag?"Yes":"No");
    }

    return 0;
}


Measured memory_bytes: 256
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n,k=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
ans=0
for i in a:
    if(i>=k):
        ans+=1
print(ans)

Measured memory_bytes: 49900
#include<bits/stdc++.h>
using namespace std;
using i64 = int64_t;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;

const i64 INF = 5e15;
 
template<typename T>
class Dijk {
private:
    template <typename U> using Edge = pair<i64, U>;
    template <typename U> using Edges = vector<Edge<U>>;
    template <typename U> using PQ = priority_queue<pair<i64, U>, vector<pair<i64, U>>, function<bool(pair<i64, U>, pair<i64, U>)>>;
     
    vector<Edges<T>> edges;
    T inf;
    T identity_ele;
         
public:
    Dijk(const vector<Edges<T>> &edges, T inf, T identity_ele)
        : edges(edges),
          inf(inf),
          identity_ele(identity_ele) {}
 
    vector<T> dijk(i64 start) {
        vector<T> d(edges.size(), inf);
        d[start] = identity_ele;
        PQ<T> q([&](const Edge<T> &a, const Edge<T> &b) {return a.second > b.second;});
        q.push(make_pair(start, 0));
        while(q.size()) {
            i64 now;
            T dis;
            tie(now, dis) = q.top();
            q.pop();
            if(d[now] < dis) {
                continue;
            }
            for(const auto &e : edges[now]) {
                i64 nxt;
                T cost;
                tie(nxt, cost) = e;
                if(d[nxt] == inf || dis + cost < d[nxt]) {
                    d[nxt] = dis + cost;
                    q.push(make_pair(nxt, dis + cost));
                }
            }
        }
        return d;
    }
};
 
int main() {
    i64 N, M, R;
    cin >> N >> M >> R;
    VV<pair<i64, i64>> edges(N);
    for(i64 i = 0; i < M; i++) {
        i64 a, b, c;
        cin >> a >> b >> c;
        edges[a].emplace_back(b, c);
    }
    auto dist = move(Dijk<i64>(edges, INF, 0).dijk(R));
    for(i64 d : dist) {
        if(d == INF) cout << "INF";
        else cout << d;
        cout << '\n';
    }
    return 0;
}



Measured memory_bytes: 30828
N = int( input() )
S = [ input() for i in range( N ) ]
mcnt = [ int( 1e9 ) for i in range( 26 ) ]
for i in range( N ):
  cnt = [ 0 for j in range( 26 ) ]
  for j in range( len( S[ i ] ) ):
    cnt[ ord( S[ i ][ j ] ) - ord( 'a' ) ] += 1
  for j in range( 26 ):
    mcnt[ j ] = min( mcnt[ j ], cnt[ j ] )
ans = ""
for i in range( 26 ):
  if mcnt[ i ] == int( 1e9 ): continue
  for j in range( mcnt[ i ] ):
    ans += chr( ord( 'a' ) + i )
print( ans )


Measured memory_bytes: 40176
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <bitset>
#include <tuple>
#include <stack>
#include <utility>

using namespace std;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> P(N);
    for(int i=0; i<N; i++) cin >> P[i];
    int a=0, b=0, c=0;
    for(int i=0; i<N; i++){
        if(P[i] <= A) a += 1;
        else if(P[i] >= B+1) c += 1;
        else b += 1;
    }
    cout << min(min(a,b), c) << endl;
    return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> ai(n,vector<int>(n));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> ai[i][j];
    }
  }
  vector<LL> dp(1<<n,0);
  dp[0]=1;
  vector<list<int>> q(n+1);
  for(int i=0;i<(1<<n);i++){
    int c=0;
    for(int j=0;j<n;j++){
      if(i&(1<<j)) c++;
    }
    q[c].push_back(i);
  }
  for(int i=1;i<=n;i++){
    for(auto no:q[i]){
      for(int j=0;j<n;j++){
        if(no&(1<<j)){
          if(ai[i-1][j]){
            dp[no]=(dp[no]+dp[no-(1<<j)])%MOD;
          }
        }
      }
    }
  }
  cout << dp[(1<<n)-1] << endl;
  return 0;
}


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

int n, q;
int A[100000];

void add(int i, int x) {
	A[i] += x;
}
void getsum(int s, int t) {
	int sum;
	if (s > t) {
		swap(s, t);
	}
	if (s == t) {
		cout << A[s] << endl;
		return;
	}
	sum = 0;
	for (int i = s;i < t + 1;i++) {
		sum += A[i];

	}
	cout << sum<< endl;
}
int main() {
	cin >> n >> q;
	int com, x, y;
	for (int i = 0;i < n;i++) {
		A[i] = 0;
	}
	for (int i = 0;i < q;i++) {
		cin >> com >> x >> y;
		if (com == 0) {
			add(x, y);
		}
		else {
			getsum(x, y);
		}
	}
	return 0;
}



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

int main(void) {
  string s;
  getline(cin, s);
  if (count(s.begin(), s.end(), '5') == 2 && count(s.begin(), s.end(), '7') == 1) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std ;

int main(){
	
	int n , m ;
	int s[20002] = {} ;
	int max ;
	
	while(1){
		cin >> n >> m ;
		if( n==0 && m==0 ) break ;
		
		for( int i=0 ; i<n ; i++ ) cin >> s[i] ;
		for( int i=n ; i<n+m ; i++ ) cin >> s[i] ;
		
		sort( s , s+n+m ) ;
		max = s[0] ;
		
		for( int i=0 ; i<n+m-1 ; i++ ){
			if( max < abs( s[i]-s[i+1] ) ) max = abs( s[i]-s[i+1] ) ;
		}
		
		cout << max << endl ;
	}
	
return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int ans = INF;
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    for(int i=0;i<n-m+1;++i) {
        int tmp = 0;
        for(int j=0;j<m;++j) {
            if(s[i+j] != t[j]) ++tmp;
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3656
X = int(input())
if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)
elif 1800 <= X <= 1999:
    print(1)

Measured memory_bytes: 9184
import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def no():
    print('No')
    exit()

def main():
    s=list(input())
    n=len(s)
    s1=s[:n//2]
    s2=s[(n+3)//2-1:]
    for i in range(n//2):
        if s1[i]!=s2[i]: no()
    print('Yes')
            



if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
Sp = input()
T = input()

if len(T) > len(Sp):
	print("UNRESTORABLE")
	exit()
	
oklist = []
for i in range(len(Sp) - len(T), -1, -1):
	for j in range(len(T)):
		if Sp[i + j] != "?" and Sp[i + j] != T[j]:
			break
	else:
		okpre = ["a" if Sp[k] == "?" else Sp[k] for k in range(i)]
		oksuf = ["a" if Sp[k] == "?" else Sp[k] for k in range(i + len(T), len(Sp))] 
		oklist.append("".join(okpre) + T + "".join(oksuf))

if oklist:
	print(min(oklist))
else:
	print("UNRESTORABLE")

Measured memory_bytes: 63360
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back

int main(){
    
    // 1. 入力情報.
    int sx, sy, tx, ty;
    scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
    
    // 2. イルカの最短経路を一つ求める.
    // 2-1. 右方向: (tx - sx)回
    string ans = "";
    rep(i, tx - sx) ans.pb('R');
    
    // 2-2. 上方向: (ty - sy)回
    rep(i, ty - sy) ans.pb('U');
    
    // 2-3. 左方向: (tx - sx)回
    rep(i, tx - sx) ans.pb('L');
    
    // 2-4. 下方向: (ty - sy)回
    rep(i, ty - sy) ans.pb('D');
    
    // 2-5. 下方向: 1回
    ans.pb('D');
    
    // 2-6. 右方向: (tx - sx + 1)回
    rep(i, tx - sx + 1) ans.pb('R');
    
    // 2-7. 上方向: (ty - sy + 1)回
    rep(i, ty - sy + 1) ans.pb('U');
    
    // 2-8. 左方向: 1回
    ans.pb('L');
    
    // 2-8. 上方向: 1回
    ans.pb('U');
    
    // 2-9. 左方向: (tx - sx + 1)回
    rep(i, tx - sx + 1) ans.pb('L');
    
    // 2-10.下方向: (ty - sy + 1)回
    rep(i, ty - sy + 1) ans.pb('D');
    
    // 2-11.右方向: 1回
    ans.pb('R');
    
    // 3. 出力.
    printf("%s\n", ans.c_str());
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
int a[10];
map<string,int> p;
int main(){
    int n;cin>>n;
    p["AC"]=1;
    p["WA"]=2;
    p["TLE"]=3;
    p["RE"]=4;
    for(int i=1;i<=n;i++){
        string s;cin>>s;a[p[s]]++;
    }
    cout<<"AC"<<" x "<<a[1]<<endl;
    cout<<"WA"<<" x "<<a[2]<<endl;
    cout<<"TLE"<<" x "<<a[3]<<endl;
    cout<<"RE"<<" x "<<a[4]<<endl;
}

Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A,B=map(int,input().split())
    S=input().split('-')
    YesNo(len(S[0])==A and len(S[1])==B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39892