akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc112/tasks/abc112_a
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define EACH(i, n) for (auto &i: n)

int main() {
  int n;

  while (cin >> n) {
    if (n == 1) {
      cout << "Hello World" << endl;
    } else {
      int a, b;
      cin >> a >> b;
      cout << a + b << endl;
    }
  }

  return 0;
}


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

int main(){
  long long n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<long long> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  sort(a.rbegin(), a.rend());
  long long ind = a.at(p - 1);
  sort(a.begin(), a.end());
  long long out = 0;
  long long count = 1;
  long long wa = 0;
  long long ind2;
  long long count2;
  for(int i = 0; i < n - 1; i++){
    if(ind - a.at(i) > m) continue;
    if(a.at(i) == a.at(i + 1)){
      if(i == n - 2) out += count;
      count++;
      continue;
    }else{
      if(ind - a.at(i) <= m){
        if(i + p >= v){
          out += count;
          count = 1;
        }else{
          long long sa = v - (i + p);
          if(wa == 0){
            wa = sa * m;
            for(int j = i + 1; j < n - p + 1; j++){
              wa += a.at(j);
            }
            ind2 = a.at(i + 1);
          }else{
            wa = wa - a.at(i) * count - count * m;
          }
          long long ind3;
          if(wa % (n - p - i) == 0){
            ind3 = wa / (n - p - i);
          }else{
            ind3 = wa / (n - p - i) + 1;
          }
          if(ind3 - a.at(i) <= m){
            out += count;
            count = 1;
          }
          count = 1;
        }
      }
    }
  }
  cout << out + 1;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000

int main() {

	LL n, k, ncpy;
	cin>>n>>k;

	if(k > n) {

		cout<<min(n, abs(n-k))<<endl;
		return 0;
	}

	LL fac = n % k == 0 ? n/k : n/k + 1;
	cout<<abs((n-(fac*k)))<<endl;

	return 0;

	// while(1) {

	// 	 ncpy = n;
	// 	n = abs(n-k);

	// 	if(n > ncpy) break;
	// }

	//cout<<ncpy<<endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

const long long base = (long long) 1e9 + 7;

long long bin_pow(long long n, long long p){
    if(p == 1) return n;

    if(p % 2 ==0){
        long long d = bin_pow(n, p/2);
        return d % base * d % base;
    } else {
        long long d = bin_pow(n, (p-1)/2);
        return d % base * d % base * n % base;
    }
}

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

    long long m,n ;
    cin >> m >> n;

    cout << bin_pow(m, n) << "\n";
    return 0;
}

Measured memory_bytes: 3184
k = input()
z = int(k)
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print (s[z-1])

Measured memory_bytes: 3060
#計数ソート
n = int(input())
a = list(map(int, input().split()))

def countSort(a):
    N = max(a)
    c = [0]*(N+2)
    b = [0]*len(a)
    for i in a:
        c[i] += 1
    for i in range(1,len(c)):
        c[i] += c[i-1]
        
    for i in a:
        b[c[i]-1] = i
        c[i] -= 1
    print(*b)

countSort(a)


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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin>>n;
    ll ans=0;
    for(int i = 1;i <= n;++i) {
        ans+=n/i;
        if(n%i==0)--ans;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
typedef long long ll;

using namespace std;

class Edge
{
	public:
	ll cost;
	int next;

	Edge(int n,ll c)
	{
		next=n;
		cost=c;
	}
};

vector<Edge> g[1000];
bool negative[1000];
ll d[1000];
ll inf = 1e15+7;

int main()
{
	int n,m;
	ll ans;
	bool f=false;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		ll c;
		cin>>a>>b>>c;
		a--;
		b--;
		c*=-1;
		g[a].push_back(Edge(b,c));
	}
	fill(d,d+1000,inf);
	d[0]=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<g[j].size();k++)
			{
				Edge e =g[j][k];
				if(d[j]!=inf && d[e.next]>d[j]+e.cost)
				{
					d[e.next]=d[j]+e.cost;
				}
			}
		}
	}
	ans = d[n-1];
	//negative loop
	fill(negative,negative+1000,false);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<g[j].size();k++)
			{
				Edge e = g[j][k];
				if(d[j]!=inf && d[e.next]>d[j]+e.cost)
				{
					d[e.next]=d[j]+e.cost;
					negative[e.next]=true;
				}

				if(negative[j])
					negative[e.next]=true;
			}
		}
	}
	if(negative[n-1])
		cout<<"inf"<<endl;
	else
		cout<<-1*ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat May 30 22:45:01 JST 2020
 **/

template <class T> std::vector<std::pair<T, int>> run_length_encode(const std::vector<T>& a) {
    std::vector<std::pair<T, int>> ret;
    int cur = 0;
    for (int i = 0; i < a.size(); i++) {
        cur++;
        if (i == a.size() - 1 || a[i] != a[i + 1]) {
            ret.emplace_back(a[i], cur);
            cur = 0;
        }
    }
    return ret;
}
std::vector<std::pair<char, int>> run_length_encode(const std::string& a) {
    std::vector<std::pair<char, int>> ret;
    int cur = 0;
    for (int i = 0; i < a.size(); i++) {
        cur++;
        if (i == a.size() - 1 || a[i] != a[i + 1]) {
            ret.emplace_back(a[i], cur);
            cur = 0;
        }
    }
    return ret;
}

signed main() {
    std::vector<int> a = {2, 2};
    std::string t;
    std::cin >> t;
    auto ps = run_length_encode(t);
    dump(ps);
    Int rem = 0, cur_zero = 0;
    std::vector<Int> zeros;
    for (auto& p : ps) {
        if (p.first == '0') {
            cur_zero += p.second;
        } else {
            rem += p.second / 2;
            if (p.second % 2) {
                zeros.push_back(cur_zero);
                cur_zero = 0;
            }
        }
    }
    zeros.push_back(cur_zero);
    Int one = std::count(t.begin(), t.end(), '1');
    Int zero = t.size() - one;
    // 全部1になってから
    Int ans = (one / 2) * (one / 2 + 1);
    if (one % 2) ans += (one + 1) / 2;
    // rem
    ans += rem * zero;
    // その他
    REP(i, zeros.size()) {
        ans += i * zeros[i];
    }
    Int acc = 0;
    REP(i, zeros.size() - 1) {
        acc += zeros[i];
        ans += (acc + i % 2) / 2;
    }
    std::cout << ans << std::endl;
}


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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

vector<vector<bool>> garden(110,vector<bool> (110,false));
int n;

void dfs(int i, int j){
	if(i>=n)return ;
	if(!garden[i][j])return ;
	garden[i][j] = false;
	dfs(i+1, j);
}

int main(){
	cin>>n;
	int max_height = 0;
	rep(i,n){
		int h; cin>>h;
		rep(j,h){
			garden[i][j] = true;
		}
		max_height = max(max_height,h);
	}
	int ans = 0;
	rep(j,max_height+1){
		rep(i,n){
			if(garden[i][j]){
				++ans;
				dfs(i+1,j);
			}
		}
	}
	cout<<ans<<endl; 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
#define M 1000'000'007

ll dp[1000009][4];  // i番目まで　0だけ使った　９だけつかった　　両方使った 未だどっちも使ってない

int n;

int main() {
    cin >> n;
    dp[1][0] = 1;
    dp[1][1] = 1;
    dp[1][2] = 0;
    dp[1][3] = 8;
    repc2(i, 2, n) {
        rep(j, 4) {
            rep(k, 10) {
                if (k == 0) {
                    if (j == 0) {
                        dp[i][j] += dp[i - 1][0] + dp[i - 1][3];
                    } else if (j == 1) {
                        //
                    } else if (j == 2) {
                        dp[i][j] += dp[i - 1][1] + dp[i - 1][2];
                    } else if (j == 3) {
                        //
                    }

                } else if (k == 9) {
                    if (j == 0) {
                        //
                    } else if (j == 1) {
                        dp[i][j] += dp[i - 1][0] + dp[i - 1][3];
                    } else if (j == 2) {
                        dp[i][j] += dp[i - 1][0] + dp[i - 1][2];
                    } else if (j == 3) {
                        //
                    }
                } else {
                    if (j == 0) {
                        dp[i][j] += dp[i - 1][0];
                    } else if (j == 1) {
                        dp[i][j] += dp[i - 1][1];
                    } else if (j == 2) {
                        dp[i][j] += dp[i - 1][2];
                    } else if (j == 3) {
                        dp[i][j] += dp[i - 1][3];
                    }
                }
                dp[i][j] %= M;
            }
        }
    }
    cout << dp[n][2] << endl;
    return 0;
}

Measured memory_bytes: 34652
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>
#include<map>

using namespace std;

typedef long long int64;

int main(void){
    int64 N,M;
    cin>>N>>M;
    vector<int64> A(N);
    vector<pair<int64,int64>> CB(M);
    int64 ans=0;

    for(int64 i=0;i<N;i++){
        cin>>A[i];
    }
    int64 b,c;
    for(int64 i=0;i<M;i++){
        cin>>b>>c;
        CB[i]=make_pair(c, b);
    }

    
    sort(CB.begin(),CB.end());
    reverse(CB.begin(),CB.end());

    int64 j=0;
    int64 tmp=0;

    while(tmp<=N){
        for(int64 i=0;i<CB[j].second;i++){
            A.push_back(CB[j].first);
            tmp++;
            //cout<<CB[j].first<<endl;
            if(tmp>N) break;
        }
        j++;
        if(j>=M) break;
    }

    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());

    for(int64 i=0;i<N;i++){
        ans+=A[i];
    }

    

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

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

typedef complex<double> P;

P in(){
	double x,y;
	cin >> x >> y;
	return P(x,y);
}
double cross(P a,P b){
	return imag(a*conj(b));
}
int main(){
	int N;
	cin >> N;
	while(N--){
		P a,b,c,d;
		a = in();
		b = in();
		c = in();
		d = in();
		if( abs(cross(a-b,c-d))<1e-12) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
		
}

Measured memory_bytes: 3088
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n=0,m=0;
	while(cin>>n>>m)
	{
		int t=1<<m;
		int ans=t*(1900*m+(n-m)*100);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
bool isprime(long long a) {
  return 1;
  for (long long i = 2; i <= sqrt(a); i++) {
  
    if (!(a%i)) {
      return 0;
    }
  }
 
  return 1;
}
 
int main() {

  #define int long long
  
  int n,m,k,ans=1;
  cin >> n >> m;

  k = __gcd(m,n);
  for (int i = 2; i <= sqrt(k); i++) {
    if(!(k%i)) {
        ans++;
        while (!(k%i)) {
          k/=i;
        }

      // if (k/i!=i && isprime(k/i)) {
      //   ans++;
      //   while (!(k%i)) {
      //     k/=i;
      //   }
      // }

    }
  }
  if (k>1) ans++;

  //skip:
  cout << ans;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int a, p;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> p;
	p += a * 3;
	cout << p / 2 << '\n';
	return 0;
}

Measured memory_bytes: 256
import itertools

N = int(input())
data = [[int(e) for e in input().split(" ")] for _ in range(N)]

ans = 0
cnt = 0
for path in itertools.permutations([i for i in range(N)]):
    dis = 0
    cnt += 1
    for i in range(N - 1):
        u = path[i]
        v = path[i + 1]

        dis += ((data[u][0] - data[v][0]) ** 2 +
                (data[u][1] - data[v][1]) ** 2)**(1 / 2)

    ans += dis

ans /= cnt
print(ans)


Measured memory_bytes: 74660
import math
n = int(input())
x, y = [int(e) for e in input().split()], [int(e) for e in input().split()]
total_1 = total_2 = total_3 = total_max = 0
for x1, y1 in zip(x, y):
    total_1 += abs(x1 - y1)
    total_2 += (x1 - y1)**2
    total_3 += (abs(x1 - y1))**3
    if total_max < abs(x1 - y1):
        total_max = abs(x1 - y1)
print("{0:.5f}".format(total_1))
print("{0:.5f}".format(math.sqrt(total_2)))
print("{0:.5f}".format(math.pow(total_3, 1.0/3.0)))
print("{0:.5f}".format(total_max))



Measured memory_bytes: 5704
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105000;

int n;
int l[MAXN], r[MAXN];
vector< pair<int, pair<int, int>> > v;
int ans = 0;
int mnEnd = 1e9;
set < pair<int, int> > r1, l2, r2;
int mxL, mnR;

int main() { 

  scanf("%d", &n);

  mxL = 0; mnR = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &l[i], &r[i]);
    ans = max(ans, r[i] - l[i] + 1);
    mnEnd = min(mnEnd, r[i]);
    l2.insert({l[i], i});
    r2.insert({r[i], i});
    if (l[i] > l[mxL]) {
      mxL = i;
    }
    if (r[i] < r[mnR]) {
      mnR = i;
    }
  }

  int mxLen = 0;
  for (int i = 0; i < n; i++) {
    if (i != mxL && i != mnR) {
      mxLen = max(mxLen, r[i] - l[i] + 1);
    }
  }
  // cerr << mxLen << " " << mnR << " " << mxL << endl;
  ans = max(ans, mxLen + max(0, r[mnR] - l[mxL] + 1));

  for (int i = 0; i < n; i++) {
    v.push_back({l[i], {r[i], i}});
  }
  sort(all(v));

  for (int i = 0; i < n; i++) {
    int idx = v[i].second.second;
    int from = v[i].first, to = r[idx];
    if (from > mnEnd) {
      break;
    }

    r1.insert({to, idx});
    l2.erase({from, idx});
    r2.erase({to, idx});

    if (sz(l2) > 0) {
      int cur = r1.begin()->first - from + 1;
      int mxL = l2.rbegin()->first;
      int mnR = r2.begin()->first;  
      cur += max(0, mnR - mxL + 1);
      ans = max(ans, cur);
      //cerr << "upd " << idx << " " << cur << endl;
      //cerr << r1.begin()->first - from + 1 << " " << mnR - mxL + 1 << endl;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,D;cin>>A>>B>>C>>D;
    //cout<<(C-1)/B<<" "<<(A-1)/D<<endl;
    if((C-1)/B>(A-1)/D)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

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

struct Item{
  int value;
  int weight;
};

int max(int x ,int y)
{
  if(x>=y)
    return x;
  else return y;
}

int main()
{
  int N,W;
  int i,w;
  struct Item *item;
  scanf("%d %d",&N,&W);
  int C[N+1][W+1];
  item=malloc(sizeof(item)*(N+1));
  for(i=1;i<=N;i++)
    scanf("%d %d",&item[i].value,&item[i].weight);

  for(w=0;w<=W;w++)
    C[0][w]=0;

  for(i=1;i<=N;i++)
    C[i][0]=0;

  for(i=1;i<=N;i++)
    for(w=1;w<=W;w++)
      if(item[i].weight<=w){
	
	C[i][w]=max(C[i-1][w],max(item[i].value+C[i-1][w-item[i].weight],item[i].value+C[i][w-item[i].weight]));
      }
      else{
	C[i][w]=C[i-1][w];
      }

  printf("%d\n",C[N][W]);

  return 0;
}

Measured memory_bytes: 4544
// Aizu 2100: Saizo
// 2017.9.20 bal4u@uu

#include <stdio.h>

int main()
{
	int t, n, h, h0, d, up, dn;

	scanf("%d", &t);
	while (t-- > 0) {
		scanf("%d%d", &n, &h0), up = dn = 0;
		while (n-- > 1) {
			scanf("%d", &h);
			if ((d = h - h0) > 0) { if (d > up) up = d; }
			else          { d = -d; if (d > dn) dn = d; }
			h0 = h;
		}
		printf("%d %d\n", up, dn);
	}
	return 0;
}

Measured memory_bytes: 1804
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    char c;
    cin >> c;
    cout << ((char)(c+1)) << endl;
}

Measured memory_bytes: 256
n=int(input());s=[]
def listpu(s):
  ans=[]
  for i in s:
    if not i in ans:ans.append(i)
  return sorted(ans)
def listsa(a,b):
  x=[]
  for i in a:
    if i in b:x.append(i)
  return sorted(x)
for i in range(n):
  s.append(input())
  if i==0:b=listpu(s[0])
  else:b=listsa(b,listpu(s[i]))
a=[100]*len(b)
for i in range(len(b)):
  for j in s:
    c=0
    for h in j:
      if h==b[i]:c+=1
    a[i]=min(a[i],c)
ans=""
for i in range(len(a)):ans+=b[i]*a[i]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long int pow107 = (int)pow(10, 9) + 7;
long int limit = LONG_MAX;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

//最大limit
//10^9+7    pow107
//素数pn
//n乗jou
//コンビネーションfactorial
//

int main(){
    vector <string> v;
    int n;
    cin >> n;

    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        v.push_back(s);
    }
    const int h = n;
    int x[h][26] = {};

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < v[i].size(); ++j){
            x[i][v[i][j] - 'a']++;
        }
    }
    int min[26] = {};
    for(int i = 0; i < 26; ++i){
        min[i] = x[0][i];
        for(int j = 1; j < v.size(); ++j){
            if(min[i] > x[j][i])
                min[i] = x[j][i];
        }
    }
    for(int i = 0; i < 26; ++i){
        for(int j = 0; j < min[i]; ++j){
            cout << char('a' + i);
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 500005
#define INF 16843009
#define LL long long
#define len(l,r) (r-l+1)
#define P int(1e9+7)
using namespace std;
 
int N,L;
double A,B;
LL t[MAXN], v[MAXN];
double ans[MAXN];

double mix(int v1, double t1, int v2, double t2){
	return (v1*t1 + v2*t2)/(v1 + v2);
}

struct Node{
	LL v;
	double t;
	
	Node(LL v, double t):v(v), t(t){}
};

deque<Node> q;

int main(){
	//freopen("1.in", "r", stdin);
	//freopen("1.ans", "w", stdout);
	
	cin>>N>>L;
	for(int i=1;i<=N;i++){
		cin>>t[i]>>v[i];
	}
	
	double t1,v1;
	for(int i=1;i<=N;i++){
		while(B > L-v[i]){
			if(q.front().v <= B-L+v[i]){
				A -= q.front().v * q.front().t;
				B -= q.front().v;
				q.pop_front(); 
			}
			else{
				q.front().v -= (B-L+v[i]);
				A -= (B-L+v[i]) * q.front().t;
				B -= (B-L+v[i]);
			}
		}
		
		//cout<<"i: "<<i<<" "<<A<<" "<<B<<endl;
		t1 = t[i]; v1 = v[i];
		while(!q.empty() && q.back().t > t1){
			t1 = mix(v1,t1, q.back().v,q.back().t);
			v1 += q.back().v;
			
			A -= q.back().v * q.back().t;
			B -= q.back().v;
			q.pop_back(); 
		}
		//cout<<"(v1,t1)"<<v1<<" "<<t1<<endl;
		A += v1 * t1;
		//cout<<"A = "<<A<<endl;
		B += v1;
		q.push_back(Node(v1,t1));

		ans[i] = A/B;
	}
	
	for(int i=1;i<=N;i++){
		printf("%.6f\n", ans[i]);
	}
	 
	
	return 0;
}

Measured memory_bytes: 28432
N = int(input())
MOD = 10 ** 9 + 7

def f(n, m):
    ans = 1
    for _ in range(m):
        ans *= n
        ans %= MOD
    return ans

ans = f(10, N) - 2 * f(9, N) + f(8, N)
ans %= MOD
print(ans)


Measured memory_bytes: 9168
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll n, k;
ll a[200005];
ll b[200005];
ll d[200005];
ll ans;
vector<ll> ve;

void f(ll p)
{
    while(p <= n)
    {
        d[p]++;
        p += (p & (-p));
    }
}

ll g(ll p)
{
    ll re = 0;
    while(p > 0)
    {
        re += d[p];
        p -= (p & (-p));
    }
    return re;
}

int main()
{
    scanf("%lld%lld", &n, &k);
    b[0] = 1;
    for(ll i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
        a[i] -= k;
        b[i] = b[i - 1] + a[i];
        ve.push_back(b[i]);
    }
    sort(ve.begin(), ve.end());
    ve.erase(unique(ve.begin(), ve.end()), ve.end());
    for(ll i = 0; i <= n; i++)
    {
        b[i] = lower_bound(ve.begin(), ve.end(), b[i]) - ve.begin() + 1;
        ans += g(b[i]);
        f(b[i]);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 6640
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int a, b, c, k;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	if(a < b)	swap(a, b);
	if(a < c)	swap(a, c);
	printf("%d\n", (a << k) + b + c);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int x[100+20];	int max1=0;
		for(int i=0;i<n;i++)
		{
		scanf("%d",&x[i]);
		max1+=x[i];
		}
		if(max1%10)
		{
		printf("%d\n",max1);
		continue;
		}
		sort(x,x+n);
		int flag=1;
		for(int i=0;i<n;i++)
		{
			if(x[i]%10!=0)
			{
				max1-=x[i];
				flag=0;
				break;
			}
		}
		if(flag==0)
		printf("%d\n",max1);
		else
		printf("0\n");
	}
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define Em empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define Fi first
#define Se second
#define Pi acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>

void FAST();
LL big_mod(LL val,LL pow,LL mod);
LL mod_inverse(LL val,LL mod);









int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,a,b,t,cnt=0;
    cin >> a >> b >> t;
    i=a,cnt=0;
    while(i <= t)
    {
        cnt+=b;
        i+=a;
    }
    cout << cnt ;
    return 0;
}







void FAST()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

LL big_mod(LL val,LL pow,LL mod)
{
    LL res = 1;
    val = val % mod;
    while(pow > 0)
    {
        if(pow & 1)
        {
            res = (res*val) % mod;
        }
        pow = pow >> 1;
        val = (val*val) % mod;
    }
    return res;
}

LL mod_inverse(LL val,LL mod)
{
    LL mod1 = mod;
    if(mod == 1)
    {
        return 0;
    }
    LL y = 0;
    LL x = 1;
    LL quotient,temp;
    while(val > 1)
    {
        quotient = val / mod;
        temp = mod;
        mod = val % mod;
        val = temp;
        temp = y;
        y = x - quotient * y;
        x = temp;
    }
    if(x < 0)
    {
        x += mod1;
    }
    return x;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    map<int,int> m;
    m[a[n-1]-(n-1)]++;
    ll ans = 0;
    rrep(i,n-1) {
        int now = -i-a[i];
        if(m.count(now)) ans += m[now];
        m[a[i]-i]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 12668
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


a,b,c,d,k=mp()
print(c*60+d-a*60-b-k)

Measured memory_bytes: 72904
//vinay
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define flash ios::sync_with_stdio(false);cin.tie(0);
//typedef const int

int main() {
	ll t, d,cnt = 0, p = 0;
	cin >> t >> d;
	ll z, x, y;
	while(t--){
	   cin >> x >> y;
	   //z = ;
	    if(d*d >= (x*x)+ (y*y)) {
	       cnt++;
	      }
	    else {
	     p++;
	    }
	 }
	cout << cnt << endl;
}


Measured memory_bytes: 3536
#include <iostream>

using namespace std;

int main() {
    int64_t n, a;

    cin >> n >> a;

    int64_t min = a, max = a, sum = a;

    for (int64_t i = 1; i < n; i++) {
        cin >> a;
        if (a < min)
            min = a;
        if (max < a)
            max = a;
        sum += a;
    }

    cout << min << " " << max << " " << sum << endl;
}

Measured memory_bytes: 3068
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type card struct {
	suit  string
	value int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	bs := make([]card, n)
	ss := make([]card, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		rs := []rune(sc.Text())
		suit := string(rs[0])
		value, _ := strconv.Atoi(string(rs[1]))
		bs[i] = card{suit: suit, value: value}
		ss[i] = card{suit: suit, value: value}
	}
	bubbleSort(bs, n)
	print(bs, n, true)

	selectionSort(ss, n)
	stable := true
	for i, v := range bs {
		if v != ss[i] {
			stable = false
			break
		}
	}
	print(ss, n, stable)
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	return num
}

func print(ary []card, n int, stable bool) {
	s := ary[0].suit + strconv.Itoa(ary[0].value)
	for i := 1; i < n; i++ {
		s += " " + ary[i].suit + strconv.Itoa(ary[i].value)
	}
	fmt.Println(s)
	if stable {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}

func bubbleSort(ary []card, n int) {
	flag := true
	for i := 0; flag; i++ {
		flag = false
		for j := n - 1; i+1 <= j; j-- {
			if ary[j].value < ary[j-1].value {
				ary[j], ary[j-1] = ary[j-1], ary[j]
				flag = true
			}
		}
	}
}

func selectionSort(ary []card, n int) {
	for i := 0; i < n-1; i++ {
		minj := i
		for j := i; j < n; j++ {
			if ary[j].value < ary[minj].value {
				minj = j
			}
		}
		if i < minj {
			ary[i], ary[minj] = ary[minj], ary[i]
		}
	}
}



Measured memory_bytes: 1104
#include<iostream>
    #include<cstdlib>
    #include<math.h>
    #include<set>
    #include<string>
    #include<stdlib.h>
    using namespace std ;
    int main(){
      int P,Q,R;
      cin>>P>>Q>>R;
      cout<<min(min(P+Q,Q+R),R+P)<<endl;
      return 0;
    }

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

llong n;
llong cnt = 0;

int main() {

    cin >> n;

    llong tmp = n;
    llong i = 2;
    llong ans = 0;
    while (i * i <= tmp && n > 1) {
        llong m = 1;
        llong cnt = 0;
        while (n % i == 0) {
            cnt++;
            if (cnt >= m) {
                cnt = 0;
                ans++;
                m++;
            }
            n /= i;
        }

        i++;
    }

    if (n > 1) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a;
  int z;
  for(int i = 0 ; i < n ; i++){
    if( s.at(i) == 'A' ){
      a = i;
      break;
    }
  }
  for(int i = 0 ; i < n ; i++){
    if( s.at(i) == 'Z' &&  z < i){
      z = i;
    }
  }
  cout << z - a + 1 << endl;
}

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


vector<int> x(10), y(10);

double distance(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx*dx+dy*dy, 0.5);
}

int main() {
    int N; cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> x[i] >> y[i];
    }

    vector<int> v(N);
    for (int i = 0; i < N; ++i) {
        v[i] = i + 1;
    }

    int cnt=1;
    for (int i = 1; i <= N; ++i) {
        cnt *= i;
    }

    double dis_sum= 0.0;
    do {
        for (int i = 0; i < N - 1; ++i) {
            dis_sum += distance(v[i], v[i+1]);
        }
    } while (next_permutation(v.begin(), v.end()));

    cout << setprecision(10) << dis_sum / cnt << endl;
    return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let i: Vec<i32> = read_vec();
    if (i[0] * i[1]) < i[2] {
        println!("{}",i[0] * i[1]);
    }else {
        println!("{}",i[2]);
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x,k,d;cin>>x>>k>>d;
  ll cnt = abs(x)/d;
  if(cnt > k){
    cout<<abs(x)-k*d<<endl;
    return 0;
  }
  k-=cnt;
  if(k%2){
    cout<<abs(abs(x)%d-d)<<endl;
  }else{
    cout<<abs(x)%d<<endl;
  }
  return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
const int MX = 2001;
int ans,k,m,n,u,v;
int g[MX][MX];
void dfs(int now,int pre,int dep) {
    m++;
    if (dep==0) return ;
    for (int i=1;i<=g[now][0];++i)
        if (g[now][i]!=pre) dfs(g[now][i],now,dep-1);
}
int main() {
    scanf("%d%d",&n,&k);
    for (int i=1; i<n; ++i) {
        scanf("%d%d",&u,&v);
        g[u][++g[u][0]]=v;
        g[v][++g[v][0]]=u;
    }
    if (k&1) {
        for (int i=1; i<=n; ++i)
            for (int p=1;p<=g[i][0];++p)
                if (g[i][p]>i) {
                    m=0;
                    dfs(i,g[i][p],k/2);
                    dfs(g[i][p],i,k/2);
                    if (m>ans) ans=m;
                    if (ans==n) break;
                }
    } else {
        for (int i=1; i<=n; ++i) {
            m=0;
            dfs(i,0,k/2);
            if (m>ans) ans=m;
            if (ans==n) break;
        }
    }
    printf("%d\n",n-ans);
    return 0;
}


Measured memory_bytes: 14208
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
i64 A[55];

i64 rup(i64 a, i64 b)
{
	return a / b + (a % b ? 1 : 0);
}

bool check(i64 step)
{
	i64 ret = 0;
	for (int i = 0; i < N; ++i) {
		ret += rup(max(0LL, A[i] + step - (N - 1)), N + 1);
	}
	return ret <= step;
}

bool checkrelka(i64 step)
{
	for (int i = 0; i < 100; ++i) {
		if (check(step - i)) return true;
	}
	return false;
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%lld", A + i);
	}

	i64 left = 0, right = 1e18;
	while (left < right) {
		i64 mid = (left + right) / 2;
		if (checkrelka(mid)) {
			right = mid;
		} else {
			left = mid + 1;
		}
	}

	i64 ret = left;
	for (int i = 0; i < 100; ++i) {
		if (check(left - i)) ret = left - i;
	}
	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const ll INFL=1e17;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
	int n; cin>>n;
	ll a[400];
	FOR(i,0,n) cin>>a[i];
	ll dp[401][401];
	ll b[401];
	b[0]=0;
	FOR(i,0,n) b[i+1]=a[i]+b[i];
	FOR(i,1,n+1){
		FOR(j,0,n-i+1){
			if(i==1){
				dp[j][j+i]=0;
			}else{
				ll m=INFL;
				FOR(k,1,i){
					m=min(m,dp[j][j+k]+dp[j+k][j+i]+b[j+i]-b[j]);
				}
				dp[j][j+i]=m;
			}
		}
	}
	co(dp[0][n]);
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
vector<long long> calc_divisor(long long n) {//約数列挙
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}
int main(){
    ll n,m;
    cin >> n >> m;
    ll ans = 1;
    for(auto u : calc_divisor(m)){
        if(u*n<=m) ans = u;
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll X, A, B;
    cin >> X >> A >> B;
    string ans = "delicious";
    if (A < B)
        ans = "safe";
    if (A + X < B)
        ans = "dangerous";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int SOSU(int);

int main(){
  int n,i,a,count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(SOSU(a))count++;
  }
  printf("%d\n",count);

  return 0;
}

int SOSU(int x){
  int i;

  if(x<2)return 0;
  else if(x==2)return 1;
  if(x%2==0)return 0;
  for(i=3;i*i<=x;i+=2){
    if(x%i==0)return 0;
  }
  return 1;
}
    



Measured memory_bytes: 2104
#include<stdio.h>

int main()
{
	int n;
	scanf("%d", &n);
	if (n == 1)
		printf("1");
	else if (n < 4)
		printf("2");
	else if (n < 8)
		printf("4");
	else if (n < 16)
		printf("8");
	else if (n < 32)
		printf("16");
	else if (n < 64)
		printf("32");
	else
		printf("64");
	return 0;
}

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


const ll MOD = 1e9 + 7;
template<ll MOD> struct ModInt {
    ll value;
    ModInt() : value(0) {}
    ModInt(const ll& v) : value(v % MOD) {
        if ( value < 0 ) value += MOD;
    }
    ModInt<MOD>& operator=(const ModInt& o) {
        value = o.value;
        return *this;
    }
    inline bool operator==(const ModInt& o) {
        return value == o.value;
    }
    inline bool operator!=(const ModInt& o) {
        return value != o.value;
    }
    ModInt<MOD>& operator+=(const ModInt& o) {
        value += o.value;
        if ( value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator-=(const ModInt& o) {
        value += MOD - o.value;
        if (value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator*=(const ModInt& o) {
        value *= o.value;
        value %= MOD;
        return *this;
    }
    ModInt<MOD>& operator/=(const ModInt& o) {
        value *= inverse(o.value);
        value %= MOD;
        return *this;
    }
    ModInt<MOD> operator-() {
        return ModInt<MOD>(-value);
    }
    ModInt<MOD> operator+(const ModInt& o) {
        ModInt<MOD> r(*this);
        r += o;
        return r;
    }
    ModInt<MOD> operator-(const ModInt& o) {
        ModInt<MOD> r(*this);
        r -= o;
        return r;
    }
    ModInt<MOD> operator*(const ModInt& o) {
        ModInt<MOD> r(*this);
        r *= o;
        return r;
    }
    ModInt<MOD> operator/(const ModInt& o) {
        ModInt<MOD> r(*this);
        r /= o;
        return r;
    }
    ModInt<MOD> pow(ll n) {
        ModInt<MOD> t(*this), r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) r *= t;
            t *= t;
            n >>= 1;
        }
        return r;
    }
private:
    ll inverse(ll a) {
        ModInt<MOD> t(a);
        return t.pow(MOD - 2).value;
    }
};
template<ll MOD> std::ostream& operator<< (std::ostream& os, const ModInt<MOD>& o) {
    os << o.value;
    return os;
}
template<ll MOD> std::istream& operator>> (std::istream& is, ModInt<MOD>& o) {
    is >> o.value;
    return is;
}

using Int = ModInt<MOD>;


ll solve() {
    ll N, a;
    cin >> N;
    vector<int> A(N);
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < N; j++ ) {
            cin >> a;
            if ( a ) A[i] |= (1 << j);
        }
    }
    int B = 1 << N;
    vector<Int> dp(B);
    dp[0] = 1;
    
    for ( int b = 0; b < B; b++ ) {
        int i = __builtin_popcount(b);
        int ab = (~b) & A[i];
        for ( int j = 0; j < N; j++ ) {
            if ( (ab >> j) & 1 ) {
                dp[b | (1<<j)] += dp[b];
            }
        }
    }
    return dp[B-1].value;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int main(){
    long N, M;
    cin >> N >> M;
    vector<pair<long, long>> S(N);
    for(auto& i : S)cin >> i.first >> i.second;

    long ans(0);

    sort(S.begin(), S.end());
    for_each(S.begin(), S.end(), [&M, &ans](auto a){long k = min(M, a.second); ans += k * a.first; M -= k;});
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) scanf("%d", &v)
#define OUT(v) printf("%d\n", v)

int main() {
  int N, C, K;
  IN(N); IN(C); IN(K);

  int T[N];
  REP(i, N) IN(T[i]);
  sort(T, T+N);

  int ans = 0;
  REP(i, N) {
    int s = T[i];
    int c = 1;
    while (s + K >= T[i+c] && c+1 <= C) ++c;
    i += c - 1;
    ++ans;
  }
  OUT(ans);

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

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

    ll N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<string> s(N);
    Rep (i, N) {
        cin >> s[i];
    }

    string ans;
    bool flag = true;

    Rep (i, N) {
        if (s[i] == "AB") {
            if (A == 0 and B == 0) flag = false;
            else if (A == 0) {
                ans += 'A';
                A++; B--;
            } else if (B == 0) {
                ans += 'B';
                A--; B++;
            } else if (A > B) {
                ans += 'B';
                B++; A--;
            } else if (A == 1 and B == 1) {
                if (i+1 < N and s[i+1] == "BC") {
                    ans += 'B';
                    B++; A--;
                } else {
                    ans += 'A';
                    A++; B--;
                }
            } else {
                ans += 'A';
                A++; B--;
            }
        } else if (s[i] == "BC") {
            if (C == 0 and B == 0) flag = false;
            else if (B == 0 or C > B) {
                ans += 'B';
                B++; C--;
            } else if (C == 1 and B == 1) {
                if (i+1 < N and s[i+1] == "AB") {
                    ans += 'B';
                    B++; C--;
                } else {
                    ans += 'C';
                    C++; B--;
                }
            } else {
                ans += 'C';
                C++; B--;
            }
        } else {
            if (A == 0 and C == 0) flag = false;
            else if (C == 0 or A > C) {
                ans += 'C';
                C++; A--;
            } else if (A == 1 and C == 1) {
                if (i+1 < N and s[i+1] == "AB") {
                    ans += 'A';
                    A++; C--;
                } else {
                    ans += 'C';
                    C++; A--;
                }
            }  else {
                ans += 'A';
                A++; C--;
            }
        }
    }

    if (flag == false) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for (char c : ans) {
            cout << c << "\n";
        }
    }
}

Measured memory_bytes: 6700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100000;
struct edge {
	int to, len, nxt;
}eg[maxn * 2 + 10];
int h[maxn + 10], egcnt;
int n, sz[maxn + 10], fa[maxn + 10], minv = 1e9, minid;
ll ans;
bool fd;

inline void addeg(int &h, int to, int len) {
	eg[++egcnt] = (edge){to, len, h};
	h = egcnt;
}

void dfssz(int p) {
	sz[p] = 1;
	for (int i = h[p]; i; i = eg[i].nxt)
		if (eg[i].to != fa[p]) {
			fa[eg[i].to] = p;
			dfssz(eg[i].to);
			sz[p] += sz[eg[i].to];
		}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int l, r, w; scanf("%d%d%d", &l, &r, &w);
		addeg(h[l], r, w); addeg(h[r], l, w);
	}
	dfssz(1);
	for (int i = 2; i <= n; ++i) {
		int w;
		for (int j = h[i]; j; j = eg[j].nxt)
			if (eg[j].to == fa[i]) w = eg[j].len;
		ans += 2ll * w * min(sz[i], n - sz[i]);
		if (sz[i] * 2 == n) {
			fd = 1; ans -= w;
		}
	}
	if (fd) {
		printf("%lld", ans);
		return 0;
	}
	for (int i = 1; i <= n; ++i) {
		int ans = n - sz[i];
		for (int j = h[i]; j; j = eg[j].nxt)
			if (eg[j].to != fa[i]) ans = max(ans, sz[eg[j].to]);
		if (ans < minv) {
			minv = ans; minid = i;
		}
	}
	minv = 1e9;
	for (int i = h[minid]; i; i = eg[i].nxt)
		minv = min(minv, eg[i].len);
	printf("%lld", ans - minv);
}


Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   

    int r;
    cin >> r;
    cout << r * r << endl;
}

Measured memory_bytes: 256
/*#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
using namespace std;

char ar[1000][1000];
int dp[1000][1000],h,w;

int solve(int r, int d)
{
	if(ar[r][d]=='#')
		return 0;
	if(r==0 || d==0)
		return 1;
	if(dp[r][d]!=-1)
		return dp[r][d];
	else return dp[r][d]=solve(r-1,d)+solve(r,d-1);
}

int main()
{
    int i,j;
    ll ans=0;
    cin>>h>>w;
    f(i,0,h)
    	f(j,0,w)
    	{
    		cin>>ar[i][j];
    		dp[i][j]=-1;
    	}
    f(i,0,h)
    	dp[i][0]=1;
    f(i,0,w)
    	dp[0][i]=1;
    
    cout<<solve(h-1,w-1);
}
*/


#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
using namespace std;

char ar[1000][1000];
int dp[1000][1000],h,w;

int main()
{
    int i,j,x=1,y=0;
    cin>>h>>w;
    f(i,0,h)
    	f(j,0,w)
    		cin>>ar[i][j];
    f(i,0,h)
    	f(j,0,w)
    		if(ar[i][j]!='#')
    		{
    			if(i-1>=0)
    				x=dp[i-1][j];
    			if(j-1>=0)
    				y=dp[i][j-1];
    			dp[i][j]=(x+y)%mod;
    			x=y=0;
    		}

    /*f(i,0,h)
    {
    	f(j,0,w)
    		cout<<dp[i][j]<<' ';
    	cout<<endl;
    }*/
    cout<<dp[h-1][w-1]%mod;
}

Measured memory_bytes: 5120