akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

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

        int[][] A = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                A[i][j] = sc.nextInt();
            }
        }

        final int N = sc.nextInt();
        int[] b = new int[N];
        for (int i = 0; i < N; i++) {
            b[i] = sc.nextInt();
        }

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < N; k++) {
                    if (A[i][j] == b[k]) {
                        A[i][j] = 0;
                    }
                }
            }
        }

        if (A[0][0] + A[0][1] + A[0][2] == 0
        || A[1][0] + A[1][1] + A[1][2] == 0
        || A[2][0] + A[2][1] + A[2][2] == 0
        || A[0][0] + A[1][0] + A[2][0] == 0
        || A[0][1] + A[1][1] + A[2][1] == 0
        || A[0][2] + A[1][2] + A[2][2] == 0
        || A[0][0] + A[1][1] + A[2][2] == 0
        || A[0][2] + A[1][1] + A[2][0] == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <list>
#include <set>
#include <queue>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
#include <vector>
#include <cctype>
#include <algorithm>
#define ll             long long
#define _              ios_base::sync_with_stdio(0);cin.tie(0);
#define loop           for(i=0;i<n;i++)
#define pb             push_back
#define tc()           int t;cin>>t;while(t--) 
#define pi             acos(-1)         
 
using namespace std;
 
ll i,j,temp;

 
int main(){_

	int s,w;
	cin>>s>>w;
	if(w>=s){
		cout<<"unsafe\n";
	}
	else{
		cout<<"safe\n";
	}

	return 0;

}

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

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

  int a[4]; 
  
  rep(i, 4){
    a[3-i] = N % 10;
    N /= 10;
  }
  

  string op[3];

  for(int tmp = 0; tmp < (1 << 3); tmp++){
    bitset<3> bits(tmp);
    int sum = a[0];
    
    rep(i, 3){
      if(bits.test(i)){
        sum += a[i+1];
        op[i] = '+';
      }
      else{
        sum -= a[i+1];
        op[i] = '-';
      }
    }
    
    if(sum == 7){
      cout << a[0] << op[0] 
           << a[1] << op[1]
           << a[2] << op[2]
           << a[3] << "=7"
           << endl;
      break;
    }
      
  }
}

  

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}
// vector<ll> js;
ll ma = 0,n;
// void dfs(int k,ll sum, ll len){
//   ma = max(ma,sum*len);
//   if(len == 0) return;
//   REP(i,k+1,n){
//     rep(j,k) cout << "\t";
//     debug(i);
// //     debug(js[i]);
// //     debug((len+js[i])*(sum-1));
//     if((len + js[i]) * (sum - 1) > sum * len){
//       dfs(i+1,len+js[i],sum-1);
//     }
//     dfs(i+1,sum,len);
//   }
// }
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll p,j;
  while(cin >> n&&n){
    vary(ll,ps,n,0);
    vector<pair<ll,int>> js(n);
//     js = vector<ll>(n);
    ll len = 0,sum = 0;
    ma = 0;
    rep(i,n){
      cin >> ps[i];
      len += ps[i];
      ++sum ;
    }
    rep(i,n-1){
//       cin >> js[i];
      cin >> js[i].fi;
      js[i].se = i;
    }
    sort(all(js));
    reverse(all(js));
    rep(i,n-1){
      if(len * sum < (len + js[i].fi) * (sum - 1)){
        len += js[i].fi;
        --sum;
      }
      else
        break;
    }
    cout << len * sum << endl;
//     dfs(-1,sum,len);
//     cout << ma << endl;
  }
  return 0;
}

Measured memory_bytes: 4532
def dfs(l,N):
    if len(l)==N:
        x.append(int("".join(map(str,l))))
        return
    else:
        for n in range(1,N+1):
            if n not in l:
                l.append(n)
                dfs(l,N)
                l.pop()

def main():
    N=int(input())
    P=list(input().strip().split())
    Q=list(input().strip().split())
    global x
    x=[]
    dfs([],N)
    x.sort()
    a=x.index(int("".join(P)))
    b=x.index(int("".join(Q)))
    return abs(a-b)

if __name__=="__main__":
    print(main())

Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
struct UnionFind{
    vl par;
    UnionFind(ll N):par(N,-1){}
    void init(ll N){par.assign(N,-1);}
    ll root(ll x){
        if(par[x]<0)return x;
        return par[x]=root(par[x]);
    }
    bool issame(ll x,ll y){
        return root(x)==root(y);
    }
    bool merge(ll x,ll y){
        x=root(x),y=root(y);
        if(x==y)return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
    ll size(ll x){
        return -par[root(x)];
    }
};
int main(){
    ll N,Q;cin>>N>>Q;
    UnionFind tree(N);
    while(Q--){
        ll a,b,c;cin>>a>>b>>c;
        if(a)cout<<(tree.issame(b,c)?1:0)<<endl;
        else tree.merge(b,c);
    }
    return 0;
}


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

typedef long long ll;

#define N 1010

char S[N];
int last[30];
vector<int> f[N];

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

		
int main()
{
	scanf("%s",S+1);
	int len=(int)strlen(S+1),Ans=len;
	for(int i=1;i<=len;i++)
	{
		int now=S[i]-'a';
		f[now].push_back(i);
	}
	for(int i=0;i<26;i++)
	{
		if(!f[i].size())
			continue;
		int Max=f[i][0]-1;
		for(int j=1;j<f[i].size();j++)
			Max=max(Max,f[i][j]-f[i][j-1]-1);
		Max=max(Max,len-f[i][f[i].size()-1]);
		Ans=min(Ans,Max);
	}
	cout<<Ans<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long sum1,sum2,n;
struct jgt{
	long long a,b,sum;
}p[100005];

bool cmp(jgt a,jgt b) {
	return a.sum>b.sum;
}

int main() {
	cin>>n;
	for (int i=1;i<=n;i++) {
		cin>>p[i].a>>p[i].b;
		p[i].sum=p[i].a+p[i].b;
	}
	sort(p+1,p+n+1,cmp);
	for (int i=1;i<=n;i+=2) {
		sum1+=p[i].a;
	}
	for (int i=2;i<=n;i+=2) {
		sum2+=p[i].b;
	}
	cout<<sum1-sum2;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    cout << (e - a > k ? ":(" : "Yay!");
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> values = new ArrayList<>();
        for (int i=0; i<N; i++) {
            values.add(scanner.nextInt());
        }

        values.sort(Comparator.comparingInt(o -> o));
        Stack<Integer> stack = new Stack<>();
        stack.addAll(values);
        int aliceSum = 0;
        int bobSum = 0;

        while (!stack.empty()) {
            aliceSum += stack.pop();
            if (stack.empty()) break;
            bobSum += stack.pop();
        }
        System.out.println(aliceSum - bobSum);
    }
}

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

int main(){
    int N,K;cin>>N>>K;//dp[i][j][k] i日目(1≦i≦N)までにパスタjをk日(k=1または2)連続で食べているときのそれまでの予定の数の総和
    int A,B;
    long long dp[101][4][3]={};
    int x[101]={};//i日目のパスタが何か
    for(int i=1;i<=N;i++){
        cin>>A>>B;
        x[A]=B;
    }
    if(x[1]) dp[1][x[1]][1]=1;//1日目のパスタの予定が決まっているとき、1日目までの予定の総和は当然1)
    else for(int i=1;i<=3;i++){
        dp[1][i][1]=1;
    }
    for(int i=2;i<=N;i++){
        if(x[i]){//配列x[i]にすでに値が入ってるかどうかで場合分け
                //なぜほとんど同じことしてるのに場合分けが必要かというと
                //代入したx[i]のデータを使っていかないと上で作った1日目の
                //初期値だけではdp配列の作成が困難なためと思われる。
            for(int j=1;j<=3;j++){
                if(x[i]==j){//前のパスタと同じなら3つめの添え字が2の場合を足すはずがない
                            //2日連続で食べたものが2日連続で食べたものから割り出されることはない
                        dp[i][j][2]+=dp[i-1][j][1]%10000;
                }
                else{
                    for(int k=1;k<=2;k++){
                        dp[i][x[i]][1]+=dp[i-1][j][k]%10000;
                    }
                }
            } 
        }
        else{
            for(int j=1;j<=3;j++){
                for(int l=1;l<=3;l++){
                    if(j==l){
                        dp[i][j][2]+=dp[i-1][j][1]%10000;
                    }
                    else{
                        for(int k=1;k<=2;k++){
                            dp[i][j][1]+=dp[i-1][l][k]%10000;
                        }
                    }
                }
            }
        }
    }
    //パスタと連続で食べた回数の6通りの組み合わせの総和が答え
    long long ans=0;
    for(int i=1;i<=3;i++){
        for(int j=1;j<=2;j++){
            ans+=dp[N][i][j];
        }
    }
    cout<<ans%10000<<endl;
    return 0;
}


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

int main() {
	int64_t a, b;
	cin >> a >> b;
	if (a > b) swap(a, b);
	//aとbの最大公約数をもとめる
	int64_t gcd = 0;
	while (true) {
		if (b%a==0) {
			gcd = a;
			break;
		}
		else {
			b = b % a;
			if (a > b) swap(a, b);
		}
	}
	//最大公約数の素因数分解をもとめる
	set<int64_t> p;
	int64_t i = 2;
	while (i <= sqrt(gcd)) {
		if (gcd % i == 0) {
			p.insert(i);
			gcd /= i;
		}
		else i++;
	}
	if(gcd>=2)p.insert(gcd);
	cout << p.size()+1 << endl;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  char a[h][w];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << a[i][j];
    }
    cout << endl;
    for(int j = 0; j < w; j++){
      cout << a[i][j];
    }
    cout << endl;
  }
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;
const int price[] = {10, 50, 100, 500};

int p;

int calc(int pr) {
	if (pr < 0) return 0;
	int res = 0;
	for (int i = 3;i >= 0;i--) {
		res += pr / price[i];
		pr %= price[i];
	}
	return res;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int s = 0;
	while (1) {
		cin >> p;
		if (p == 0) break;
		VI as;
		if (s > 0) cout << endl;
		rep (i, 4) {
			int a;
			cin >> a;
			as.pb(a);
		}
		VI ans(4);
		int max_v = INF;
		rep (i, as[0] + 1) rep (j, as[1] + 1) rep (k, as[2] + 1) rep (l, as[3] + 1) {
			int pr = price[0] * i + price[1] * j + price[2] * k + price[3] * l;
			int cnt = as[0] -  i + as[1] -  j + as[2] -  k + as[3] -  l;
			int sum = cnt + calc(pr - p);
			if (pr >= p && sum < max_v) {
				ans[0] = i;
				ans[1] = j;
				ans[2] = k;
				ans[3] = l;
				max_v = sum;
			}
		}
		rep (i, 4) {
			if (ans[i] == 0) continue; 
			cout << price[i] << " " << ans[i] << endl;
		}
		s++;
	}
	return 0;
}

Measured memory_bytes: 3116
N = int(input())
prime_cnt = [0] * 1000
ans = 0
for i in range(2, N + 1):
    work = i
    for j in range(2, int(i ** (1 / 2)) + 1):
        while work % j == 0:
            prime_cnt[j - 1] += 1
            work //= j
    if work != 1:
        prime_cnt[work - 1] += 1
# print(prime_cnt)
ans = 1
mod = 10 ** 9 + 7
for cnt in prime_cnt:
    if cnt:
        ans *= (cnt + 1)
        ans %= mod
print(ans)

Measured memory_bytes: 9360
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(),v.end()
#define PI acos(-1)

const ll INF = 10010001010;

ll lcm(ll a,ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> ans(N);
    X--;
    Y--;
    for (int sv = 0; sv < N;sv++)
    {
        vector<ll> dist(N, INF);
        queue<int> que;
        auto push = [&](int v, int d) {
            if(dist[v] != INF)
            {
                return;
            }
            else
            {
                dist[v] = d;
                que.push(v);
            }
        };
        push(sv, 0);
        while(!que.empty()){
            int v = que.front();
            que.pop();
            int d = dist[v];
            if(v-1 >= 0){
                push(v - 1, d + 1);
            }
            if(v+1 < N){
                push(v + 1, d + 1);
            }
            if(v==X){
                push(Y, d + 1);
            }
            if(v == Y){
                push(X, d + 1);
            }
        }
        for (int i = 0; i < N;i++)
        {
            ans[dist[i]]++;
        }
    }
    for (int i = 1; i < N;i++)
    {
        ans[i] /= 2;
    }
    for (int i = 1; i <= N - 1;i++)
    {
        cout << ans[i] << endl;
    }
}

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

int main() {
 string N ;
 cin >>N ;
 if(N.at(0)!='7'&&N.at(1)!='7'&&N.at(2)!='7') 
 cout <<"No" <<endl;
 else
  cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;


using namespace std;

#define BUFF ios::sync_with_stdio(false)
#define rep(i,a,b) for (int i=a; i<b; i++)
#define pb push_back
#define vvi vector<vector<int>> 
#define vi vector<int>
#define vb vector<bool>
#define vvb vector<vector<bool>> 

vi visit, pos;
int nxt = 1;
void dfs_visit(vvi & adj, int i, int cor) {
	visit[i] = cor;
	for (int j : adj[i]) {
		if (!visit[j]) {
			dfs_visit(adj, j, cor);
		}
	}
	pos[i] = nxt++;
}

void dfs(vvi & adj, int n) {
		visit.assign(n+1, 0);
		pos.assign(n+1, 0);
		int cor=0;
		for(int i=1; i<=n; i++) {
			if (!visit[i]) {
				cor++;
				dfs_visit(adj, i, cor);
			}
		}
		cout << cor-1 << endl;
}

int main() {
	int n, m;
	cin >> n >> m;

	vvi adj;
	vi lista;
	lista.clear();
	adj.assign(n+1, lista);
	for (int i=1; i<=m; i++) { 
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	dfs(adj, n);

}


Measured memory_bytes: 10016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc()) 
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 100010;
struct edge {
  int la,b;
} con[N << 1];
int tot, fir[N];
void add_edge(int from,int to) {
  con[++tot] = (edge) {fir[from], to};
  fir[from] = tot;
}
int n, deg[N], ndeg[N], typ[N], num[N], ans[N];
deque<int> vec;
void dfs(int pos,int fa) {
  vec.push_back(num[pos]);
  for (int i = fir[pos]; i; i = con[i].la) {
    if (con[i].b == fa) continue;
    if (typ[con[i].b]) continue;
    dfs(con[i].b, pos);
  }
}
int cur[N];
void doit() {
  int cnt = 0;
  for (int i = 0, j = 0; i < (int)vec.size(); ++ i) {
    int tmp = ++ j;
    rep (a, 1, vec[i]) cur[++ cnt] = ++ j;
    cur[++ cnt] = tmp;
  }
  int key = 0;
  rep (i, 1, n) {
    if (cur[i] < ans[i]) {
      key = 1;
      break;
    } else if (cur[i] > ans[i])
      break;
  }
  if (key) rep (i, 1, n) ans[i] = cur[i];
}
int main() {
  int x,y;
  read(n);
  rep (i, 1, n-1) {
    read(x), read(y);
    add_edge(x, y);
    add_edge(y, x);
    ++ deg[x], ++ deg[y];
  }
  rep (i, 1, n) ndeg[i] = deg[i];
  rep (i, 1, n) if (deg[i] == 1) {
    typ[i] = 1;
    for (int t = fir[i]; t; t = con[t].la)
      -- ndeg[con[t].b], ++ num[con[t].b];
  }
  int key = 1, nu = 0;
  rep (i, 1, n) if (!typ[i]) {
    if (ndeg[i] > 2) key = 0;
    ++ nu;
  }
  if (!key) {
    puts("-1");
    return 0;
  }
  rep (i, 1, n) if (typ[i] == 0 && (ndeg[i] == 1 || nu == 1)) {
    dfs(i, 0);
    break;
  }
  if (vec[0] > 0) {
    -- vec[0];
    vec.push_front(0);
  }
  if (vec.back() > 0) {
    -- vec[(int)vec.size()-1];
    vec.push_back(0);
  }
  rep (i, 1, n) ans[i] = n;
  doit();
  reverse(vec.begin(), vec.end());
  doit();
  rep (i, 1, n) printf("%d ", ans[i]);
  puts("");
  return 0;
}


Measured memory_bytes: 8192
MOD = 10**9 + 7
MOD_t_MAX = 3 * (10**5)

fac  = [None] * MOD_t_MAX
finv = [None] * MOD_t_MAX
inv  = [None] * MOD_t_MAX
def MOD_COM_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MOD_t_MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
def MOD_COM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main():
    n, m = map(int, input().split())
    MOD_COM_init()
    dic = {}
    x = 2
    while m%x == 0:
        if x in dic:
            dic[x] += 1
        else:
            dic[x] = 1
        m //= x
    x = 3
    while x*x <= m:
        while m%x == 0:
            if x in dic:
                dic[x] += 1
            else:
                dic[x] = 1
            m //= x
        x += 2
    if 1 < m:
        if m in dic:
            dic[m] += 1
        else:
            dic[m] = 1
    ans = 1
    for v in dic.values():
        ans *= MOD_COM(n+v-1, v)
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 38644
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <unordered_map>

using namespace std;

int minDistance(string word1, string word2) {
    int n = word1.size(), m = word2.size();
    if(n == 0) return m;
    if(m == 0) return n;
    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
    for(int i = 0; i <= n; ++ i) dp[i][0] = i;
    for(int i = 0; i <= m; ++ i) dp[0][i] = i;
    for(int i = 1; i <= n; ++ i) {
        for(int j = 1; j <= m; ++ j) {
            if(word1[i-1] == word2[j-1]) dp[i][j] = dp[i-1][j-1];
            else dp[i][j] = dp[i-1][j-1] + 1;
        }
    }
    return dp[n][m];
}

int main(){
    string s;
    string word = "CODEFESTIVAL2016";
    while(cin >> s) {
        cout << minDistance(word, s) << endl;
    }

    return 0;
}


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

int main() {
  int a;
  string b;
  cin >> a;
  
  for (int i = 0; i < a; i++){
    cin >> b;
    if (b == "Y"){
      cout << "Four" << endl;
      break;
    }
  }
  if (b != "Y")  cout << "Three" << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



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;
}

long long solve(long long N) {
    const auto &div1 = calc_divisor(N-1);
    const auto &div2 = calc_divisor(N);
    long long res = (int)div1.size() - 1; // 1 を除外
    for (auto d : div2) {
        if (d == 1) continue;
        long long NN = N;
        while (NN % d == 0) NN /= d;
        if ((NN-1) % d == 0) ++res;
    }
    return res;
}

int main() {
    long long K;
    while (cin >> K) cout << solve(K) << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
  
  int i,j,num,num2,count=0,key;
  int NUM[100001],NUM2[50001];
  
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&NUM[i]);
    
  }
  
  scanf("%d",&num2);
  
  for(i=0;i<num2;i++){
    scanf("%d",&key);

    int left=0,right=num,mid;
    while(left<right){
      mid=(left+right)/2;
      if(NUM[mid]==key){
	count++;
	break;
      }
      else if(key<NUM[mid])
	right=mid;
      else left = mid + 1;
    }
  }
  printf("%d\n",count);  
  return 0;
}

Measured memory_bytes: 988
import java.util.Scanner;

/**
 * https://abc056.contest.atcoder.jp/tasks/abc056_b
 */
public class Main {
	 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);		
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		int ans = 0;
		if(a+w<b){
			ans = b-(a+w);
		}else if(b+w<a){
			ans = a-(b+w);
		}
	
		System.out.println(ans);
 
	}
 
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int n;
    cin>>n;
    bool visit[3][3];
    memset(visit,false,sizeof(visit));
    while(n--){
        int x;
        cin>>x;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                 if(a[i][j]==x){
                     visit[i][j]=true;
                     break;
                 }
            }
        }
    }
    for(int i=0;i<3;i++){
        int count=0;
        for(int j=0;j<3;j++){
            if(visit[i][j]==true){
                count++;
            }
        }
        if(count==3){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
     for(int i=0;i<3;i++){
        int count=0;
        for(int j=0;j<3;j++){
            if(visit[j][i]==true){
                count++;
            }
        }
        if(count==3){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if(visit[0][0]==true && visit[1][1]==true && visit[2][2]==true){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(visit[0][2]==true && visit[1][1]==true && visit[2][0]==true){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
llint c[200005];
llint sum[200005];
llint dp[200005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> c[i];
	
	vector<llint> vec;
	for(int i = 1; i <= n; i++){
		if(c[i] != c[i-1]) vec.push_back(c[i]);
	}
	int n = vec.size();
	for(int i = 1; i <= n; i++) c[i] = vec[i-1];
	
	dp[0] = 1;
	for(int i = 1; i <= n; i++){
		sum[c[i]] += dp[i-1], sum[c[i]] %= mod;
		dp[i] = sum[c[i]];
	}
	cout << dp[n] << endl;
	
	return 0;
}

Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//ll mod = 1000000007;
ll mod = 998244353;

signed main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    bool is_minus_even = true;
    bool is_zero_exist = false;
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] < 0)
        {
            is_minus_even = !is_minus_even;
        }
        if (a[i] == 0)
        {
            is_zero_exist = true;
        }
    }
    ll ans = 0;
    if (is_minus_even == true || (!is_minus_even && is_zero_exist))
    {
        rep(i, n)
        {
            ans += abs(a[i]);
        }
    }
    else
    {
        rep(i, n)
        {
            a[i] = abs(a[i]);
        }
        sort(all(a));
        ans = accumulate(a.begin() + 1, a.end(), 0LL) - a[0];
    }
    cout << ans << endl;
    return 0;
}

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

int main(void) {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while (A > 0 && C > 0) {
		C -= B;
		if (C <= 0) break;
		A -= D;
	}

	cout << (A > C ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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; }

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/
const int IMAX = 2000000;
int H[IMAX],W[IMAX];
int X[IMAX],Y[IMAX];
int a[IMAX],b[IMAX];
int N,M;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    while(1){
        cin>>N>>M;
        if(N==0&&M==0)break;
        rep(i,max(N,M) + 5){
            X[i] = Y[i] = 0;
        }
        rep(i,IMAX){
            a[i] = b[i] = 0;
        }
        rep(i,N){
            cin>>H[i];
            Y[i+1] += H[i] + Y[i];
        }
        rep(i,M){
            cin>>W[i];
            X[i+1] += W[i] + X[i];
        }
        map<int,int> map;
        for(int i = 0; i <= N; i++){
            for(int j = 0; j <= M; j++){
                map[Y[i]-X[j]]++;
            }
        }
        ll ans = 0;
        for(auto p:map){
            ans += p.second * (p.second-1) /2;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 45504
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

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

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

    string str;

    while(cin >> str)
    {
		if(str.back() == '3') printf("bon\n");
		else if(str.back() == '0' || str.back() == '1' || str.back() == '6' || str.back() == '8') printf("pon\n");
		else printf("hon\n");
    }


}




Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;

int keta(long long int Num){
  int ans=0;
  do{
    ans++;
    Num=Num/10;
  }while(Num!=0);
  return ans;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int N;
  cin>>N;
  int ans=keta(N);
  for(int i=sqrt(N);i>=2;i--){
    if(N%i==0){
      ans=keta(N/i);
      break;
    }
  }
  cout<<ans;

  return 0;
}

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

a = []
for x in range(0, N):
  a.append(input())

b = []
for x in range(0, M):
  b.append(input())

exists = []
for i in range(0, len(a)):
  exists.append([i, a[i].find(b[0])])

for x, y in exists:
  ari = []
  for i in range(0, len(b)):
    if x+i < len(a):
      ari.append(a[x+i][y:y+M])
  if "".join(ari) == "".join(b):
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 3064
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

void z_function(string const &s,int* z)
{
    int n = (int) s.length();
    z[0] = n;
    for (int i = 1, l = 0, r = 0; i < n; ++i)
    {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }

}
int main()
{
    int i,n,t,k,j,x=0,y=0,m;
    FAST
    string str;
    cin>>n>>str;
    int ans = 0;
    for(i=0;i<n;i++)
    {
        int z[10000];
        memset(z,0,sizeof z);
        string temp = str.substr(i,n-i);

        z_function(temp,z);
        for(j=1;j<temp.size();j++)
        {
            ans = max(ans,min(j,z[j]));
        }

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



Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
const int maxn=1e5+5;
int main()
{
    string s;
    cin>>s;
    int n=(s[0]-'0')*10+(s[1]-'0');
    int m=(s[2]-'0')*10+(s[3]-'0');
   //1700 cout<<n<<" "<<m<<endl;
    if(n>0&&n<=12&&m>0&&m<=12) printf("AMBIGUOUS\n");
    else if(n<=12&&n>0) printf("MMYY\n");
    else if(m<=12&&m>0) printf("YYMM\n");
    else printf("NA\n");
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef unsigned long long int ll;
typedef vector< pair<int, int> > vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef pair<int, int> pii;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int nax = 200 + 10;

int n, dist[nax][nax], m, r;
int graph[nax][nax];
vi v;

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> m >> r;
    for(int i = 1; i <= r; i++)
    {
        int num; cin >> num;
        v.pb(num);
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(i != j)
                graph[i][j] = INF;
        }
    }
    while(m--)
    {
        int u, v, c;
        cin >> u >> v >> c;
        graph[u][v] = min(c, graph[u][v]);
        graph[v][u] = min(c, graph[v][u]);
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(j == i)
            {
                dist[i][j] = 0;
                continue;
            }
            dist[i][j] = graph[i][j];
        }
    }
    for(int k = 1; k <= n; k++)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int ans = 0;
            sort(v.begin(), v.end());

      for(int i = 1; i < r; i++)
        {
            ans += dist[v[i]][v[i - 1]];
        }
    while(next_permutation(v.begin(), v.end()))
    {
        int mainans = 0;
        for(int i = 1; i < r; i++)
        {
            mainans += dist[v[i]][v[i - 1]];
        }
        ans = min(ans, mainans);

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


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 3e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, Q, T;

int main() {
	int i, j;
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d", MAX(a - 2 * b, 0));
	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	//sc.Split(bufio.ScanWords)

	people := scanNums(6)
	a := calc(people[0], people[1:6])
	fmt.Print(a)

}

func calc(n int, maxPeople []int) int {

	if len(maxPeople) == 0 {
		return 1
	}

	ans := 0
	min := maxPeople[0]
	for _, v := range maxPeople {
		if min > v {
			min = v
		}
	}

	ans += n/min + 4

	if n%min != 0 {
		ans += 1
	}
	return ans

}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func scanString() string {
	var s string
	fmt.Scan(&s)
	return s
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		str = nextString()
		strings = append(strings, str)
	}
	return
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}


Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <queue>
#include <iostream>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;


const int inf = 1e9;
// Dreyfus-Wagner. O(4^k)
// https://kopricky.github.io/code/Academic/steiner_tree.html
int steiner_tree(const vector<vector<PI> > &g, const VI &term) {
  int n = g.size();
  int k = term.size();
  vector<vector<int> > dp(n, vector<int>(1 << k, inf));
  // base case: |bits| = 1
  REP(i, 0, k) {
    dp[term[i]][1 << i] = 0;
  }
  REP(bits, 1, 1 << k) {
    REP(i, 0, n) {
      REP(sub, 1, bits) {
        if ((sub & bits) != sub) continue;
        dp[i][bits] = min(dp[i][bits], dp[i][sub] + dp[i][bits - sub]);
      }
    }
    priority_queue<PI, vector<PI>, greater<PI> > que;
    REP(i, 0, n) {
      if (dp[i][bits] < inf) {
        que.push(PI(dp[i][bits], i));
        dp[i][bits] = inf;
      }
    }
    while (not que.empty()) {
      PI dv = que.top(); que.pop();
      int d = dv.first;
      int v = dv.second;
      if (dp[v][bits] <= d) continue;
      dp[v][bits] = d;
      REP(j, 0, g[v].size()) {
        PI wc = g[v][j];
        int w = wc.first;
        int c = wc.second;
        que.push(PI(d + c, w));
      }
    }
  }
  int mi = inf;
  REP(i, 0, n) {
    mi = min(mi, dp[i][(1 << k) - 1]);
  }
  return mi;   
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  while(cin >> h >> w && h && w) {
    vector<VI> s(h, VI(w));
    REP(i, 0, h) {
      REP(j, 0, w) {
        cin >> s[i][j];
      }
    }
    vector<vector<PI> > g(h * w);
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    VI term;
    REP(i, 0, h) {
      REP(j, 0, w) {
        int v = i * w + j;
        if (s[i][j] == 1) term.push_back(v);
        REP(d, 0, 4) {
          int nx = i + dx[d];
          int ny = j + dy[d];
          if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
          int u = nx * w + ny;
          g[v].push_back(PI(u, 1));
        }
      }
    }
    cout << h * w - 1 - steiner_tree(g, term) << endl;
  }
}



Measured memory_bytes: 3184
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;

#define LL long long

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int INF=9999999;
const int MAXN=1000000;

int N; 
struct data{
	int t,x,y;
}a[MAXN+1]; 

int main(){
    N=read();
    for(int i=1;i<=N;i++) a[i].t=read(),a[i].x=read(),a[i].y=read();
    for(int i=1;i<=N;i++){
    	int xx=abs(a[i].x-a[i-1].x);
    	int yy=abs(a[i].y-a[i-1].y);
    	if(xx+yy>a[i].t-a[i-1].t||(a[i].t-a[i-1].t-xx-yy)&1) {
    		puts("No");
    		return 0;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[2005];
int sum[2005];
int cnt[2005];
vector<ll> dp[2];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum[i+1]+=a[i];
		sum[i+1]+=sum[i];
	}
	dp[0].push_back(1);
	int nows=1,prevs=0;
	for(int i=0;i<n;i++){
		int vi=0;
		while(vi<=sum[i+1]+100){
			dp[nows].push_back(0);
			vi+=60;
		}
		int siz=a[i]/60;
		int dif=a[i]%60;
		for(int j=0;j<dp[prevs].size();j++){
			dp[nows][j]|=dp[prevs][j];
			if(dif>0){
				dp[nows][j+siz+1]|=(dp[prevs][j]&((1LL<<60)-(1LL<<(60-dif))+1LL))>>(60-dif);
				dp[nows][j+siz]|=(dp[prevs][j]&((1LL<<(60-dif))-1LL))<<dif;
			}else{
				dp[nows][j+siz]|=dp[prevs][j];
			}
			//cout << ((dp[i][j].to_ullong()&((1LL<<dif)-1))<<dif)  << endl;
		}
		swap(nows,prevs);
		dp[nows].clear();
	}
	for(int i=0;i<dp[prevs].size();i++){
		for(int j=0;j<60;j++){
			if(dp[prevs][i]>>j & 1){
				if((i*60+j)*2>=sum[n]){
					printf("%d\n",i*60+j);
					return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1980
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,d;
	cin>>a>>b;
	d=a*500;
	if(d>=b)
	{
		cout<<"Yes";
	}
	if(d<b)
	{
		cout<<"No";
	}
	return 0;
	
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
for i in range(0,int(n/2)):
	a[i],a[n-1-i]=a[n-1-i],a[i]
for i in range(n-1):
	print(str(a[i]),end=" ")
print(str(a[n-1]))
	


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll long long

int main() {
    //入力
    vector<int> a(5);
    rep(i, 5) cin >> a[i];
    //
    int maxmod = 0;
    int maxi = 0;
    rep(i, 5) {
        if (a[i] % 10 != 0) {
            int m = 10 - a[i] % 10;
            if (m > maxmod) {
                maxmod = m;
                maxi = i;
            }
        }
    }
    int ans = 0;
    rep(i, 5) {
        if (i != maxi) {
            int m = a[i] % 10;
            if (m != 0) {
                ans += (a[i] / 10)*10 + 10;
            }
            else {
                ans += a[i];
            }
        }
    }
    ans += a[maxi];

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

Measured memory_bytes: 3600
using System;

class A10{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    long n1 = 1;
    long n2 = 1;

    if(n == 0) Console.WriteLine(n1);
    else if(n == 1) Console.WriteLine(n2);
    else{
      for(int i = 2;i <= n;i++){
        long n3 = n1 + n2;
        n1 = n2;
        n2 = n3;
      }
      Console.WriteLine(n2);
    }
  }
}



Measured memory_bytes: 15976
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
int n, m, f[100000 + 5];
int find(int x) {return x == f[x] ? x : f[x] = find(f[x]);}
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) f[i] = i;
	for (int x, y, z, i = 1; i <= m; ++i) {
		scanf("%d%d%d", &x, &y, &z);
		int a = find(x), b = find(y);
		if (a != b) f[a] = b;
	}
	for (int i = 1; i <= n; ++i) find(i);
	int ans = 0;
	for (int i = 1; i <= n; ++i) ans += (f[i] == i);
	cout << ans;
	return 0;
}

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

#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

void cominit(ll m)
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i=2; i<MAX; i++) {
    fac[i] = fac[i-1] * i % m;
    inv[i] = m - inv[m%i] * (m/i) % m;
    finv[i] = finv[i-1] * inv[i] % m;
  }
}

ll com(ll n, ll k, ll m)
{
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % m) % m;
}

void solve()
{
  cominit(mod);
  ll n,m,k;
  cin>>n>>m>>k;

  ll x=0, y=0;
  for (ll d=1; d<n; d++) {
    x += d * (n-d) % mod;
  }
  x = x * m % mod * m % mod;
  for (ll d=1; d<m; d++) {
    y += d * (m-d) % mod;
  }
  y = y * n % mod * n % mod;

  ll ans = (x+y) % mod * com(n*m-2, k-2, mod) % mod;
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 12160