akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string.h>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

vector<int> G[105];
int n;
int d[105];

void bfs(int s)
{
	fill(d, d + n, -1);
	d[s] = 0;

	queue<int> que;
	que.push(s);
	while (!que.empty()) {
		int k = que.front(); que.pop();
		for (int i = 0; i < G[k].size(); i++) {
			int j = G[k][i];
			if (d[j] == -1) {
				d[j] = d[k] + 1;
				que.push(j);
			}
		}
	}
}

int main()
{
	cin >> n;
	int u, k, v;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;
			G[u].push_back(v);
		}
	}
	bfs(0);
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << endl;
	}

	return 0;
}

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

map<string, long long>Map;
long long mod = 998244353;

string syncronization(string A1, string A2) {
	for (int i = 0; i < A1.size(); i++) A1[i] = min(A1[i], A2[i]);
	return A1;
}

long long solve(string S) {
	if (Map[S] >= 1) return Map[S] - 1;

	vector<long long>dp(S.size() + 1, 0);
	dp[0] = 1;

	for (int i = 0; i < S.size(); i++) {
		if (dp[i] == 0) continue;
		for (int j = i + 1; j <= S.size(); j++) {
			long long B = 1; if (S[i] == '1') B = 2;
			if (j - i >= 2) {
				// ここから全探索
				B = 0;
				for (int k = 1; k < (j - i); k++) {
					if ((j - i) % k >= 1) continue;
					string V = S.substr(i, k);
					for (int l = i + k; l < j; l += k) {
						string W = S.substr(l, k);
						V = syncronization(V, W);
					}
					B += solve(V); B %= mod;
				}
			}
			dp[j] += dp[i] * B;
			dp[j] %= mod;
		}
	}
	Map[S] = dp[S.size()] + 1;
	return dp[S.size()];
}

int main() {
	string S; cin >> S;
	cout << solve(S) << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int n=0;
	while(b<=a)
	{
		b*=2;
		n++;
	}	
	while(c<=b)
	{
		c*=2;
		n++;
	}
	if(n>k)
		cout<<"No"<<endl;
	else 
		cout<<"Yes"<<endl;
		return 0;	
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<stdlib.h>
#include <dirent.h>
using namespace std;
#define sp << " " << 
typedef vector<int> vi;
typedef vector<long int> vli;
typedef vector<long long int> vlli;
typedef long int li;
typedef long long int lli;
typedef vector<pair<int,int> > vpi;
typedef vector<pair<lli,lli> > vplli;
typedef unordered_map<int,int> ump;

// int findAns( vector<vector<int>> arr,  vector<vector<int>> &dp, int index, int lastSelection){
//     // cout << "called" << endl;
//     if(index>=arr.size()){
//         return 0;
//     }

//     dp[index][0] = dp[index][0]==-1? arr[index][0] + findAns(arr,dp,index+1, 0) :dp[index][0];
//     dp[index][1] = dp[index][1]==-1? arr[index][1] + findAns(arr,dp,index+1, 1) :dp[index][1];
//     dp[index][2] = dp[index][2]==-1? arr[index][2] + findAns(arr,dp,index+1, 2):dp[index][2];
//     // cout << dp[index][0] << " " << dp[index][1] << " " << dp[index][2]<< " " << index << endl;
//     if(lastSelection==0){
//         return max(dp[index][1],dp[index][2]);
//     }
//     if(lastSelection==1){
//         return max(dp[index][0],dp[index][2]);

//     }
//     if(lastSelection==2){
//         return max(dp[index][1],dp[index][0]);
//     }

//     return 0;
// }

int main(){
    int n;
    cin >> n ;
    vector<vector<int>> arr(n,vector<int>(3));
    for(int i=0;i<n;i++){
        int a,b,c;
        cin >> a >> b>>c;
        arr[i][0]=a;
        arr[i][1]=b;
        arr[i][2]=c;
    }
    vector<vector<int>> dp(n,vector<int>(3,-1));
    dp[n-1][0]=arr[n-1][0];
    dp[n-1][1]=arr[n-1][1];
    dp[n-1][2]=arr[n-1][2];
    for(int i=n-2;i>=0;i--){
        dp[i][0] = arr[i][0] + max(dp[i+1][1],dp[i+1][2]);
        dp[i][1] = arr[i][1] + max(dp[i+1][0],dp[i+1][2]);
        dp[i][2] = arr[i][2] + max(dp[i+1][0],dp[i+1][1]);
    }

    cout << max(dp[0][0], max(dp[0][1], dp[0][2]));
    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,ans=0,d[100010],e[100010]={};
  cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  fr(i,n) cin>>a[i];
  fr(i,n) cin>>b[i];
  fr(i,n) cin>>c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  fr(i,n) ans+=(lower_bound(a.begin(),a.end(),b[i])-a.begin())*(c.end()-upper_bound(c.begin(),c.end(),b[i]));
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<list>
#include<vector>
#include<stdio.h>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
	int N,M;
	cin >> N >> M;
	int a[M],b[M];
	for(int i=0;i<M;i++){
		cin >> a[i] >> b[i];
	}
	bool pos[N+1]={};
	for(int i=0;i<M;i++){
		if(a[i]==1){
			pos[b[i]] = true;
		}
	}
	for(int i=0;i<M;i++){
		if(pos[a[i]]==true){
			if(b[i]==N){
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}



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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll N;
  scanf("%lld", &N);

  map<ll, ll> m;
  // vector<ll> list(N);
  for (ll i = 0; i < N - 1; i++) {
    ll v;
    scanf("%lld", &v);
    // list[i] = v;

    m[v] += 1;
  }

  for (ll i = 1; i <= N; i++) {
    cout << m[i] << endl;
  }
}


Measured memory_bytes: 11536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    (abs(a-c)<=d||abs(a-b)<=d&&abs(b-c)<=d)? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll n; cin>>n;
    vector<ll> c={-1};
    rep(i,n){
        ll a; cin>>a;
        ll s=c.size();
        if(c[0]<a){
            c[0]=a;
            continue;
        }
        ll left=0, right=s;
        while(left+1<right){
            ll mid=(left+right)/2;
            if(a>c[mid]) right=mid;
            else left=mid;
        }
        if(right==s) c.push_back(a);
        else c[right]=a;
    }
    cout<<c.size()<<endl;
    return 0;
}

Measured memory_bytes: 1400
//OPTIMIZATONS
#pragma GCC optimize("02")
//CODE
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;

const int inf = 1e17 + 7;
const int MOD = 1e7 + 9;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n,m;
	cin>>n>>m;
	int a[n];
	int sum = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum += a[i];
	}
	int cnt = 0;
	for(int i=0;i<n;i++){
		if((a[i]*4*m)>=sum) cnt++;
	}
	if(cnt>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 256
import math

A, B, H, M = input().split()

v1 = 1/2
v2 = 6
t = 60 * float(H) + float(M)

u1 = (90 - (float(v1) * float(t)))
u2 = (90 - (float(v2) * float(t)))

o1 = math.radians(u1)
o2 = math.radians(u2)

xa = float(A) * math.cos(o1)
ya = float(A) * math.sin(o1)

xb = float(B) * math.cos(o2)
yb = float(B) * math.sin(o2)

d = math.sqrt((xa-xb)**2 + (ya-yb)**2)

print(d)


Measured memory_bytes: 9480
def main():
  s = input()
  flag = True
  count = 1
  for i in s:
      if (count % 2 == 1) and ( i == 'L'):
          flag = False
          count += 1
      elif (count % 2 == 0) and (i == 'R'):
          flag = False
          count += 1
      else:
          count += 1
  if flag:
      print('Yes')
  else:
      print('No')
      
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>

#include<stdio.h>
#include<stdlib.h>

#define ll long long

using namespace std;

int N;
vector<int> color;
vector<vector<pair<int,int>>> ki;

void dfs(int pos,int parent){
    for(int i=0;i<ki[pos].size();i++){
        if(ki[pos][i].first!=parent){
            if(ki[pos][i].second%2==0){
                color[ki[pos][i].first]=color[pos];
            }
            else{
                color[ki[pos][i].first]=!color[pos];
            }
            dfs(ki[pos][i].first,pos);
        }
    }
}

int main(){
    int N;
    cin >> N;
    color=vector<int>(N,-1);
    ki=vector<vector<pair<int,int>>>(N);
    int u,v,w;
    for(int i=0;i<N-1;i++){
        cin >> u >> v >> w;
        ki[u-1].push_back(make_pair(v-1,w%2));
        ki[v-1].push_back(make_pair(u-1,w%2));
    }
    color[0] = 0;
    dfs(0,0);
    for(int i=0;i<N;i++){
        cout << color[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
#define pii pair<int,int>
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int INF = 1e7;

namespace NetFlow
{
	const int N = 2e5+2;
	const int M = 4e5;
	struct Edge
	{
		int v,w,nxt,rev;
	} e[(M<<1)+3];
	int fe[N+3];
	int te[N+3];
	int dep[N+3];
	int que[N+3];
	int n,en,s,t;
	void addedge(int u,int v,int w)
	{
		en++; e[en].v = v; e[en].w = w;
		e[en].nxt = fe[u]; fe[u] = en; e[en].rev = en+1;
		en++; e[en].v = u; e[en].w = 0;
		e[en].nxt = fe[v]; fe[v] = en; e[en].rev = en-1;
	}
	bool bfs()
	{
		for(int i=1; i<=n; i++) dep[i] = 0;
		int head = 1,tail = 1; que[1] = s; dep[s] = 1;
		while(head<=tail)
		{
			int u = que[head]; head++;
			for(int i=fe[u]; i; i=e[i].nxt)
			{
				int v = e[i].v;
				if(e[i].w>0 && dep[v]==0)
				{
					dep[v] = dep[u]+1;
					if(v==t) return true;
					tail++; que[tail] = v;
				}
			}
		}
		return false;
	}
	int dfs(int u,int cur)
	{
		if(u==t||cur==0) {return cur;}
		int rst = cur;
		for(int &i=te[u]; i; i=e[i].nxt)
		{
			int v = e[i].v;
			if(e[i].w>0 && rst>0 && dep[v]==dep[u]+1)
			{
				int flow = dfs(v,min(rst,e[i].w));
				if(flow>0)
				{
					e[i].w -= flow;	
					rst -= flow;
					e[e[i].rev].w += flow;
					if(rst==0) {return cur;}
				}
			}
		}
		if(rst==cur) {dep[u] = -2;}
		return cur-rst;
	}
	int dinic(int _n,int _s,int _t)
	{
		n = _n,s = _s,t = _t;
		int ret = 0;
		while(bfs())
		{
			for(int i=1; i<=n; i++) te[i] = fe[i];
			memcpy(te,fe,sizeof(int)*(n+1));
			ret += dfs(s,INF);
		}
		return ret;
	}
}
using NetFlow::addedge;
using NetFlow::dinic;

const int N = 1e5;
vector<int> adj[(N<<1)+3];
vector<pair<int,pii> > ans;
int mch[(N<<1)+3];
bool vis[(N<<1)+3];
int n;

void dfs(int u)
{
	for(int o=0; o<adj[u].size(); o++)
	{
		int v = adj[u][o]; if(vis[v]) continue;
		if(vis[mch[v]]) continue;
		vis[v] = vis[mch[v]] = true; ans.push_back(mkpr(v,mkpr(u,mch[v])));
		dfs(mch[v]);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++) addedge(1,i+2,1);
	for(int i=n+1; i<n+n; i++) addedge(i+2,2,1);
	for(int i=1; i<n; i++)
	{
		int sz; scanf("%d",&sz);
		while(sz--)
		{
			int x; scanf("%d",&x); adj[i+n].push_back(x); adj[x].push_back(i+n);
			if(x!=1) {addedge(x+2,i+n+2,1);}
		}
	}
	if(dinic(n+n+1,1,2)<n-1) {puts("-1"); return 0;}
	for(int u=3; u<=n+2; u++)
	{
		for(int i=NetFlow::fe[u]; i; i=NetFlow::e[i].nxt)
		{
			int v = NetFlow::e[i].v; if(v<=n+2) continue;
			if(NetFlow::e[i].w==0)
			{
				mch[u-2] = v-2,mch[v-2] = u-2;
				break;
			}
		}
	}
//	printf("match: "); for(int i=1; i<=n+n-1; i++) printf("%d ",mch[i]); puts("");
	vis[1] = true; dfs(1);
	if(ans.size()<n-1) {puts("-1"); return 0;}
	sort(ans.begin(),ans.end());
	for(int i=0; i<ans.size(); i++) printf("%d %d\n",ans[i].second.first,ans[i].second.second);
	return 0;
}

Measured memory_bytes: 33524
import java.math.BigInteger;
import java.util.Scanner;

//A King in Hawaii
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			BigInteger b = sc.nextBigInteger();
			if(b.intValue()==-1)break;
			System.out.println(b.toString(4));
		}
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  vi ans(n, -1);
  rep (i, n) {
    int a;
    scan(a);
    ans[a - 1] = i + 1;
  }
  rep (i, n) {
    printf("%d%c", ans[i], " \n"[i == n-1]);
  }

  return 0;
}


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

using namespace std;

int N,M;

vector<int> par;
vector<int> rankk;

void init(int n){
    
    for (int i = 0; i < N; i++) {
        par.push_back(i);
        rankk.push_back(0);
    }
    
}

int find(int x){
    
    if(par[x] == x){
        
        return x;
    }else{
        
        return par[x] = find(par[x]);
    }
    
    
}

void unit(int x, int y){
    
    x = find(x);
    y = find(y);
    if (x == y) {
        return;
    }
    
    if (rankk[x] < rankk[y]) {
        par[x] = y;
    }else{
        par[y] = x;
        if (rankk[x] == rankk[y]) {
            rankk[x]++;
        }
        
    }
    
}


bool same(int x, int y){
    return find(x) == find(y);
}


int main(){
    
    cin >> N >> M;
    init(N);
    
    for (int i = 0; i < M; i++) {
        
        int a,b,c;
        cin >> a >> b >> c;
        unit(a-1, b-1);
    }
    
    
    vector<int> aa(N);
    for (int i = 0; i < N; i++) {
        aa[i] = find(par[i])-1;
    }
    
    sort(aa.begin(), aa.end());
    int ans = 1;
    
    for (int i = 0; i < N-1; i++) {
        if (aa[i] != aa[i+1]) {
            ans += 1;
        }
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 1652
#include <iostream>
#include <algorithm>
using namespace std;
int main(){

  int n,t[300010],r=1;
  cin>>n;
  for(int i=0;i<n;i++) cin>>t[i];
  int le=t[0];
  for(int i=1;i<n;i++){
    le-=10;
    if(le<0) r=0;
    le=max(le,t[i]);
  }

  reverse(t,t+n);

  le=t[0];
  for(int i=1;i<n;i++){
    le-=10;
    if(le<0) r=0;
    le=max(le,t[i]);
  }

  cout<<(r?"yes":"no")<<endl;
  return 0;


}



Measured memory_bytes: 4260
#define _USE_MATH_DEFINES////////////////////////////////////////
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

int uplg(int n) { return 32-__builtin_clz(n); }
int uplg(ll n)  { return 64-__builtin_clzll(n); }

void run() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;

	rep(i, 0, h) {
		rep(j, 0, w) {
			cout << ((i<b) ^ (j<a));
		}
		cout << '\n';
	}
}


Measured memory_bytes: 1280
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <functional>
#define SIZE 2005
#define MX 5000005
#define MOD 1000000007

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

ll inv[MX],fac[MX],finv[MX];
ll dp[SIZE][SIZE];
ll all[SIZE];

void make()
{
	inv[1]=1;
	fac[0]=fac[1]=finv[0]=finv[1]=1;
	for(int i=2;i<MX;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int a,int b)
{
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
int main()
{
	make();
	int n,K;
	scanf("%d %d",&n,&K);
	if(K==1)
	{
		puts("1");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		all[i]=0;
		ll now=all[i-1];
		for(int j=1;j<=i;j++)
		{
			if(i==1) dp[i][j]=1;
			else
			{
				ll way=C((K-2)+(i-1)*K-(j-1),K-2)*now%MOD;
				dp[i][j]=way*(ll) i%MOD;
				if(j>=2)
				{
					now-=dp[i-1][j-1];
					if(now<0) now+=MOD;
				}
			}
			all[i]+=dp[i][j];
			if(all[i]>=MOD) all[i]-=MOD;
			//printf("%lld ",dp[i][j]);
		}
		//puts("");
	}
	printf("%lld\n",all[n]);
	return 0;
}


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

int main(){
int H[100000],W[100000];
int c=0;
for(int i=1;i<100000;i++){
cin>>H[i]>>W[i];
c++;
if(H[i]==0 && W[i]==0){
goto aa;
}
}
aa:;
for(int i=1;i<c;i++){
for(int j=0;j<H[i];j++){
for(int k=0;k<W[i];k++){
    if((j==0 || j==(H[i]-1)) || (k==0 || k==(W[i]-1))){
    cout<<"#";
    }
    else{
    cout<<".";
    }
}
cout<<endl;
}
cout<<endl;
}
return 0;
}

Measured memory_bytes: 1164
#!/usr/bin/env python3
N = int(input().strip())
T, A = [int(str) for str in input().strip().split()]
H = [int(str) for str in input().strip().split()]

temp_diffs = [abs(T - h * 0.006 - A) for h in H]
print(temp_diffs.index(min(temp_diffs)) + 1)

Measured memory_bytes: 3444
<?php
list($num,$special)=explode(" ",trim(fgets(STDIN)));
$enemy=explode(" ",trim(fgets(STDIN)));


 if($num<=$special){
     echo "0";
 }else{
   rsort($enemy);
   
    for($i=0;$i<$special;$i++){
     unset($enemy[$i]);
    }
    echo array_sum($enemy); 
}

?>

Measured memory_bytes: 23200
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&a!=b)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

var (
	scanner = bufio.NewScanner(os.Stdin)
)

// nextLine は次の行を受け取り、文字列として返す関数
func nextLine() string {
	scanner.Scan()
	return scanner.Text()
}

// nextLineInt は次の行を受け取り、int型として返す関数
func nextLineInt() int {
	scanner.Scan()
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return num
}

func main() {
	// 1行を取得してint型に変換されたものをnに代入
	var lotteryNum int = nextLineInt()
	// string: int のマップをNの分だけ作成
	var lotteryKinds map[string]int = make(map[string]int, lotteryNum)

	for i := 1; i <= lotteryNum; i++ {
		var lotteryPrize string = nextLine()
		if _, state := lotteryKinds[lotteryPrize]; !state {
			lotteryKinds[lotteryPrize] = 1
		}
	}

	fmt.Println(len(lotteryKinds))
}

Measured memory_bytes: 13084
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int th[15]={0,1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
int f[100005],t;
int main()
{
	memset(f,0x3f,sizeof(f));
	scanf("%d",&n);
	for(int i=1;i<=12;i++)
		if(th[i]<=n)
			++t;
	f[0]=0;
	for(int i=1;i<=t;i++)
		for(int j=th[i];j<=n;j++)
			f[j]=min(f[j],f[j-th[i]]+1);
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <time.h>
#include <stdlib.h>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define LL_INF 1e18

#define nmax 200010

#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007
#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef long long int ll;

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

int n;
int p[nmax];

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

    for (int i = 1; i <= n; i++) scanf("%d", &p[i]);

    int answer = 0;
    int minn = INF;

    for (int i = 1; i <= n; i++) {

        if (p[i] <= minn) answer++;

        minn = min(minn, p[i]);
    }

    printf("%d", answer);

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 1024
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 330 * 330;

typedef pair <int, int> pii;

int x[MAXN], y[MAXN], ans[MAXN];

int main ()
{
    int n, m, d;
    scanf ("%d%d%d", &n, &m, &d);
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 1; j <= m; j ++)
        {
            int t;
            scanf ("%d", &t);
            x[t] = i;
            y[t] = j;
        }
    }
    memset (ans, 0, sizeof (ans));
    int all = n * m;
    for (int i = 1; i <= d; i ++)
    {
        for (int j = i + d; j <= all; j += d)
        {
            ans[j] = ans[j - d] + abs (x[j] - x[j - d]) + abs (y[j] - y[j - d]);
        }
    }
    int q;
    scanf ("%d", &q);
    for (int i = 1; i <= q; i ++)
    {
        int s, t;
        scanf ("%d%d", &s, &t);
        printf ("%d\n", ans[t] - ans[s]);
    }
    return 0;
}


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

/*RMQ  update:O(logN)  query:O(lonN)*/
const int MAX_N = 1<<20;

struct data{
  int l,r;
};

data dat[2*MAX_N-1];
int n;

//?????????
void init(int n_){
  //????´???°n???2???????????????
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)
    dat[i].l=dat[i].r=0;
}

//[a,b)
//query(a,b,0,0,n)
void query(int a,int b,int k,int l,int r,int x){
  if(r<=a||b<=l)return;
  if(a<=l&&r<=b){
    if(!dat[k].l)dat[k].l=dat[k].r=x;
    else if(dat[k].r+1==x)dat[k].r=x;
    else dat[k].l=dat[k].r=-1;
  }else{
    if(dat[k].l){
      if(!dat[k*2+1].l)dat[k*2+1].l=dat[k].l,dat[k*2+1].r=dat[k].r;
      else if(dat[k*2+1].r+1==dat[k].l)dat[k*2+1].r=dat[k].r;
      else dat[k*2+1].l=dat[k*2+1].r=-1;
      if(!dat[k*2+2].l)dat[k*2+2].l=dat[k].l,dat[k*2+2].r=dat[k].r;
      else if(dat[k*2+2].r+1==dat[k].l)dat[k*2+2].r=dat[k].r;
      else dat[k*2+2].l=dat[k*2+2].r=-1;
      dat[k].l=dat[k].r=0;
    }
    query(a,b,k*2+1,l,(l+r)/2,x);
    query(a,b,k*2+2,(l+r)/2,r,x);
  }
}

int main(){
  int k,t,l,r,x;
  cin>>n>>k>>t;
  init(n);
  for(int i=0;i<t;i++){
    cin>>l>>r>>x; l--,r--;
    query(l,r+1,0,0,n,x);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    query(i,i+1,0,0,n,k+1);
    if(dat[n+i-1].l==1&&dat[n+i-1].r==k+1)
      ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7184
#include <stdio.h>

void qsort(int a[], int first, int last){
    if(first >= last)return;
    int pv = a[first], head = first+1, end = last, buf;
    while(1){
        while(head < end && pv <= a[head]) head++;
        while(head < end && pv >= a[end]) end--;
        if(head == end)break;
        buf = a[head];
        a[head] = a[end];
        a[end] = buf;
    }
    if(a[head]<pv) head--;
    a[first] = a[head];
    a[head] = pv;
    qsort(a,first,head-1);
    qsort(a,head+1,last);
    return;
}

int main(void){
    int n, i=0;
    scanf("%d",&n);
    int ans=n, a[n];
    for(; i<n; i++) scanf("%d",&a[i]);
    qsort(a, 0, n-1);
    for(i=0; i<n-1; i++){
        if(a[i] == a[i+1])ans--;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int a[n];
    int ma = 0, mi = 0;
    rep(i,n){
        cin>>a[i];
        if(a[i]>=ma){
            mi=ma;
            ma=a[i];
        }
        else if(a[i]>mi)mi=a[i];
    }
    rep(i,n){
        if(a[i]==ma)cout<<mi<<endl;
        else cout<<ma<<endl;
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  if (n == 0) ans = 1;
  if (n == 1) ans = 2;
  if (n == 2) ans = 1;
  cout << ans << endl;
}



Measured memory_bytes: 3104
n=int(input())
m=[]
a=[]
r=[]
c=[]
h=[]
for i in range(n):
    A=input()
    if A[0]=="M":
        m.append(A)
    elif A[0]=="A":
        a.append(A)
    elif A[0]=="R":
        r.append(A)
    elif A[0]=="C":
        c.append(A)
    elif A[0]=="H":
        h.append(A)
m=len(m)
a=len(a)
r=len(r)
c=len(c)
h=len(h)
ans=m*(a*r+a*c+a*h+r*c+r*h+c*h)+a*(r*c+r*h+c*h)+r*c*h
print(ans)

Measured memory_bytes: 55768
#include <stdio.h>
#include <stdlib.h>
int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}
int main(){
        int N,K;
        scanf("%d %d", &N, &K);
        int A[200000]={};
        for(int i=0;i<N;i++){
                int a;
                scanf("%d",&a);
                A[a-1]++;
        }
        qsort(A, N, sizeof(int), cmp);
        int count=0;
        for(int i=0;i<N-K;i++){
                count += A[i];
        }
        printf("%d", count);
        return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n>>k>>m;

    for(int i=1;i<=k;i++){
        cout<<m<<" ";
    }

    for(int i=k+1;i<=n;i++){
        if(m==1000000000)cout<<m-1<<" ";
        else cout<<m+1<<" ";
    }

    return 0;
}


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

void solve(int n){
    int t;
    vector<int> v,va;
    for(int i=0;i<n;i++){
        cin >> t;
        v.push_back(t);
    }
    sort(v.rbegin(),v.rend());
    for(auto itr=v.begin();itr!=v.end()-1;itr++){
        va.push_back(*itr-*(itr+1));
    }
    int mini=va.front();
    for(int x:va){
        mini=min(mini,x);
    }
    
    
    cout<<mini<<endl;
    
}

int main(void){
    int a;
    while(cin>>a,a){
        solve(a);
    }
    
    
    
}

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

int str_cmp (const void *a, const void *b) {
    return strncmp((char*)a, (char*)b, 11);
}

int main (void) {
    int n, i;
    scanf("%d", &n);
    char s[n][11];
    for ( i=0; i<n; i++ )
        scanf("%s", s[i]);
    qsort(s, n, 11*sizeof(char), str_cmp);

    int n_ans=0, n_same=1, most=0;
    char *ans[n], *cur=s[0];
    memset(ans, 0, n*sizeof(char*));
    for ( i=1; i<n; i++ ) {
        if ( strncmp(s[i-1], s[i], 11) == 0 ) {
            n_same++;
        }
        else {
            if ( n_same > most ) {
                most = n_same;
                n_ans = 0;
                ans[n_ans] = cur;
                n_ans++;
            }
            else if ( n_same == most ) {
                ans[n_ans] = cur;
                n_ans++;
            }
            cur = s[i];
            n_same = 1;
        }
    }
    if ( n_same > most ) {
        most = n_same;
        n_ans = 0;
        ans[n_ans] = cur;
        n_ans++;
    }
    else if ( n_same == most ) {
        ans[n_ans] = cur;
        n_ans++;
    }

    for ( i=0; i<n_ans; i++ )
        printf("%s ", ans[i]);
    printf("\n");

    return EXIT_SUCCESS;
}


Measured memory_bytes: 5652
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001
int main()
{
    int X, A, ans;
    scanf("%d%d",&X ,&A);
    ans = (X < A)? 0 : 10;
    printf("%d \n", ans);
    
    return 0;
}


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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int h,w,memo[50][50],cnt;
string s[50];
queue<pair<int,pair<int,int>>> que;

bool masu(int a, int b) {
    if (0 <= a && a < b) return true;
    else return false;
}

signed main() {
    cin >> h >> w;
    rep(i,h) cin >> s[i];
    rep(i,h) rep(j,w) if (s[i][j] == '.') cnt++;
    que.push(mp(1,mp(0,0)));
    while(que.size()) {
       int y = que.front().se.fi, x = que.front().se.se, a = que.front().fi;que.pop();
       if (memo[y][x]) continue;
       memo[y][x] = a;
       int dy[4]={1,0,-1,0}, dx[4]={0,1,0,-1};
       rep(i,4) {
           int Y = y+dy[i], X = x+dx[i];
           if (masu(Y,h) && masu(X,w) && s[Y][X] == '.') que.push(mp(a+1, mp(Y,X)));
       }
    }
    if (memo[h-1][w-1]) cout << cnt-memo[h-1][w-1] << endl;
    else cout << -1 << endl;
}




Measured memory_bytes: 256
N = int(input())
l = [list(map(int,input().split())) for i in range(N)]
l.sort(key = lambda x: x[2])
for x in range(101):
    for y in range(101):
        H = abs(x-l[-1][0])+abs(y-l[-1][1])+l[N-1][2]
        if all((l[i][2] == max(H-abs(x-l[i][0])-abs(y-l[i][1]),0) for i in range(N))):
            print(x,y,H)
            break
    else:
        continue
    break

Measured memory_bytes: 3064
import Data.List

hit [] [] = 0
hit (x:xs) (y:ys) =
  if x == y
  then 1 + hit xs ys
  else hit xs ys

blow' [] _ = 0
blow' _ [] = 0

blow' (x:xs) (y:ys) =
  if x == y
  then 1 + blow' xs ys
  else if x < y
       then blow' xs (y:ys)
       else blow' (x:xs) ys

blow x y = 
  let x' = sort x
      y' = sort y
  in
    blow' x' y'

chk x y =
  let h = hit  x y
      b = blow x y
  in
    [h, b-h]

ans (["0","0"]:_) = []
ans ([x,y]:s) =
  (chk x y):(ans s)

main = do
  c <- getContents
  let i = map words $ lines c
      o = ans i
  mapM_ putStrLn $ map unwords $ map (map show) o

Measured memory_bytes: 5036
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

int N, M;
vector<vector<PII> > roads;
vector<int> fast;
set<PII> s;

void seterase(int a, int b){
    if(a>b)swap(a, b);
    if(s.count(PII(a, b)))s.erase(PII(a, b));
}

void setset(int a, int b){
    if(a>b)swap(a, b);
    s.insert(PII(a, b));
}

void check(int sp){
    fast.assign(N+1, INF);
    priority_queue<PII, vector<PII>, greater<PII> > que;
    fast[sp]=0;
    que.push(PII(0, sp));
    while(que.size()){
        PII d = que.top();
        que.pop();
        if(fast[d.second]!=d.first)continue;
        foreach(i, roads[d.second]){
            int nf = d.first + i.second;
            if(fast[i.first]>nf){
                fast[i.first]=nf;
                que.push(PII(nf, i.first));
            }
        }
    }
    REPA(i, N+1){
        foreach(j, roads[i]){
            if(fast[i]-j.second == fast[j.first]){
                seterase(i, j.first);
            }
        }
    }
}

int main(){
    cin >> N >> M;
    roads.resize(N+1);
    REP(i, M){
        int a, b, c;
        cin >> a >> b >> c;
        roads[a].push_back(PII(b, c));
        roads[b].push_back(PII(a, c));
        setset(a, b);
    }

    REPA(i, N+1){
        check(i);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int n,m;
    cin >> n>>m;
    int ans = 0;
    int minn = 1e9;
    int maxn = 0;
    for (int i = 1; i <= m;i++)
    {
        int l,r;
        cin >> l >> r;
        minn = min(minn, r);
        maxn = max(maxn, l);
    }
    //cout << maxn << minn << endl;
    if(minn < maxn)
        cout << 0 << endl;
    else 
      cout << minn - maxn + 1<< endl;
    return 0;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $N);
$life = array_map('intval', explode(' ', fgets(STDIN))); //入力を数値として配列に入れる

echo all_gcd($life);

function all_gcd($life) {
    $ans = $life[0];
    for ($i = 1; $i < count($life); ++$i) {
        $ans = gcd($ans, $life[$i]);
    }
    
    return $ans;
}

//a,bどちらが大きくても問題ない
function gcd($a, $b) {
    if ($b === 0) {
        return $a;
    } else {
        return gcd($b, $a % $b);
    }
}


Measured memory_bytes: 16884
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
#include<set>

using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)

#define shosu setprecision(10)
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。
//↑はあんまり気にしなくていい。
const ll MOD = 1e9+7;
const int index = 2*1e5+1;

namespace mod{
ll add(ll a,ll b){
      return ((a%MOD)+(b%MOD))%MOD;
}

ll mul(ll a,ll b){
      return ((a%MOD)*(b%MOD))%MOD;
}

ll pow(ll a,ll b){
      if(b==0) return 1;
      else if(b%2==0){
            ll ret=pow(a,b/2);
            return ((ret%MOD)*(ret%MOD))%MOD;
      }
      else return ((pow(a,b-1)%MOD)*(a%MOD))%MOD;
}
ll div(ll a,ll b){
      return ((a%MOD)*(pow(b,MOD-2)%MOD))%MOD;
}

ll frac[index+1];
void calc(){ //main関数内にcalc();を入れること
      frac[0]=1;
      rep0(i,index){
            frac[i+1]=mul(frac[i],i+1);
      }
}
}

int main(){
      int n,m,k;
      cin>>n>>m>>k;
      ll ans=0;
      mod::calc();
      rep0(i,n){
            ans+=mod::mul(mod::mul(mod::mul(m,m),mod::mul(i,n-i)) ,mod::div( mod::frac[m*n-2] , mod::mul(mod::frac[m*n-k],mod::frac[k-2])));
            ans%=MOD;
      }
      swap(n,m);
      rep0(i,n){
            ans+=mod::mul(mod::mul(mod::mul(m,m),mod::mul(i,n-i)) ,mod::div( mod::frac[m*n-2],mod::mul(mod::frac[m*n-k],mod::frac[k-2])));
            ans%=MOD;
      }
      cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b; cin >> a >> b;
    ll k = (((b + b % 2) - (a + a % 2)) / 2) % 2;
    cout << ((a % 2 ? a : 0) ^ k ^ (b % 2 ? 0 : b)) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  for(int s = 0; s < S.size(); ++s) {
    int idx = S[s] - 'A'; // A からの場所
    idx += N;
    idx %= 26;
    cout << char('A' + idx);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

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

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            List<String> S = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                S.add(in.next());
            }
            String T = in.next();

            List<String> al = new ArrayList<>();
            List<String> zl = new ArrayList<>();
            for (String s : S) {
                al.add(s.replace('?', 'a'));
                zl.add(s.replace('?', 'z'));
            }
            al.sort(Comparator.naturalOrder());
            zl.sort(Comparator.naturalOrder());
            int ai = -1;
            int zi = 0;
            for (int i = 0; i < N; i++) {
                if (T.compareTo(al.get(i)) >= 0) {
                    zi = i + 1;
                }
                if (T.compareTo(zl.get(i)) <= 0 && ai == -1) {
                    ai = i;
                }
            }
            if (ai == -1) ai = N;
            StringBuilder sb = new StringBuilder();
            for (int i = ai; i <= zi; i++) {
                sb.append(i + 1).append(' ');
            }
            out.println(sb.subSequence(0, sb.length() - 1));
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 27348
#include<iostream>

using namespace std;

long fivo(long req){
  long dp[100001];
  dp[0]=0;
  dp[1]=1;

  int i;
     for( i=2; i<req;i++){
       dp[i]=dp[i-1]+dp[i-2];
       //       cout <<dp[i]<<" "<<"="<<dp[i-1]<<"+"<<dp[i-2]<<endl;
     }
    dp[req]=dp[req-1]+dp[req-2];

     return dp[req];

}




int main(){
  long n;
  int req;

  cin >>req;
  n=fivo(req+1);
  //  for(n=1;n<=20;n++){
  //cout<<fivo(n)<<endl;
  // }
  cout <<n<<endl;
  return 0;
}

Measured memory_bytes: 3104
#include <stdio.h>

int main() {
  char A[16], B[16], C[16];
  int ae, be;
  
  scanf("%s %s %s", A, B, C);
  
  for(ae = 0; A[ae+1] != '\0'; ae++) ;
  for(be = 0; B[be+1] != '\0'; be++) ;
  
  if(A[ae] == B[0] && B[be] == C[0]) printf("YES\n");
  else printf("NO\n");
  
  return 0;
}
  

Measured memory_bytes: 128
n, m = map(int, input().split())
edges = []
for i in range(m):
    a, b, c = map(int, input().split())
    a-=1; b-=1
    edges.append((a, b, -c))

dist = [float('inf')]*n
dist[0] = 0
for i in range(n-1): # なぜ？
    for st, en , score in edges:
        if dist[st] == float('inf'): continue
        if dist[en] > dist[st] + score:
            dist[en] = dist[st] + score

negative = [False] * n

for loop in range(n):
    for e in edges:
        st, en, score = e
        if dist[st] == float('inf'): continue
        if dist[en] > dist[st] + score:
            dist[en] = dist[st] + score
            negative[en] = True
        if negative[st]:
            negative[en] = True

if negative[n-1]:
    print('inf')
else:
    print(-dist[n-1])

Measured memory_bytes: 9292
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <numeric>

using namespace std;

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

    vector<int> pn(n);
    for(int& pi : pn){
        cin >> pi;
    }

    int result = 0;

    for(int i = 1 ; i < n - 1 ; i++){
        int max_val = max(pn[i - 1], pn[i + 1]);
        int min_val = min(pn[i - 1], pn[i + 1]);

        if((min_val < pn[i]) && (pn[i] < max_val)){
            result++;
        }     
    }

    cout << result << endl;

    return 0;
}



Measured memory_bytes: 256
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
calc=lambda u,v:min(u,v)*n+max(u,v)
edge=[[]for _ in range(n*n)]
for i in range(n):
  for j in range(1,n-1):
    u,v=calc(a[i][j-1]-1,i),calc(a[i][j]-1,i)
    edge[u].append(v)
from collections import deque
def find_loop(n,e):
  x=[0]*n
  d=deque()
  t=[]
  c=0
  for i in range(n):
    for j in e[i]:x[j]+=1
  for i in range(n):
    if x[i]==0:
      d.append(i)
      t.append(i)
      c+=1
  while d:
    i=d.popleft()
    for j in e[i]:
      x[j]-=1
      if x[j]==0:
        d.append(j)
        t.append(j)
        c+=1
  return t
d=find_loop(n*n,edge)
if len(d)!=n*n:exit(print(-1))
c=[1]*n*n
for i in d:
  for j in edge[i]:
    c[j]=c[i]+1
print(max(c))


Measured memory_bytes: 179260
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100009;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

//typedef uint64_t hash_t;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int HASH_COUNT = 2;
//const hash_t HASH_P = (uint32_t)-13337;
//uniform_int_distribution<hash_t> MULT_DIST(0.25 * HASH_P, 0.75 * HASH_P);
//const hash_t HASH_MULT[HASH_COUNT] = {MULT_DIST(rng), MULT_DIST(rng)};

int n, m, k;
int groupId;
int groupMem;

int kount[N];
int group[N];
int answer[N];

vector < int > g[N];

void dfs(int u){
  if(group[u] != 0){
    return ;
  }
  group[u] = groupId;
  groupMem++;
  for(int i = 0; i < g[u].size(); i++){
    int v = g[u][i];
    if(group[v] == 0){
      dfs(v);
    }
  }
}

int main(){
  fastScan(n);
  fastScan(m);
  fastScan(k);
  for(int i = 1; i <= m; i++){
    int u, v;
    fastScan(u);
    fastScan(v);
    g[u].pb(v);
    g[v].pb(u);
  }
  for(int i = 1; i <= n; i++){
    if(group[i] == 0){
      groupId++;
      groupMem = 0;
      dfs(i);
      kount[groupId] = groupMem;
    }
    answer[i] = kount[group[i]] - g[i].size() - 1;
  }
  for(int i = 1; i <= k; i++){
    int c, d;
    fastScan(c);
    fastScan(d);
    if(group[c] == group[d]){
      answer[c]--;
      answer[d]--;
    }
  }
  for(int i = 1; i <= n; i++){
    printf("%d%c", answer[i], (i == n ? '\n' : ' '));
  }
}


Measured memory_bytes: 7552