akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;
typedef long long lli;
const lli inf = -1e15;
int nx[1000][2],n;
lli cache[1000][2],arr[1001];

lli DP(int idx,int f) {
	lli &ret=cache[idx][f];
	if(ret != -inf) return ret;

	lli val;
	ret=arr[idx];

	lli mx = 0;
	int ni = -1;
	for(int i=idx+2;i<n;i+=2) {
		val = DP(i,1);
		if(val > mx) {
			mx=val;
			ni = i;
		}
	}
	if(mx > 0) {
		ret += mx;
		nx[idx][f]=ni;
	}

	if(idx < n-1 && !f) {
		val = DP(idx+1, 0);
		if(val > ret) {
			ret=val;
			nx[idx][f]=idx+1;
		}
	}
	return ret;
}
vector<int> ans;
void trace(int idx,int f) {
	if(nx[idx][f] == -1) {
		for(int t=n-idx;t>=2;t--) ans.push_back(t);
		return;
	}
	if(nx[idx][f] == idx+1) {
		ans.push_back(1);
		trace(idx+1,0);
	}
	else {
		for(int l=(nx[idx][f]-idx)/2;l;l--) ans.push_back(l+1);
		trace(nx[idx][f],1);
	}
}

int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",arr+i);
	for(int i=0;i<n;i++) cache[i][0]=cache[i][1] = -inf,nx[i][0]=nx[i][1]=-1;
	printf("%lld\n",DP(0,0));
	trace(0,0);
	printf("%d\n",ans.size());
	for(auto &it:ans) printf("%d\n",it);

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k,a;
    cin >> n >> k;
    vector<ll> c(n);
    rep(i,n) cin >> c[i];
    ll ans = INF;
    rep(i,n-k+1){
        chmin(ans,min(abs(c[i]),abs(c[i+k-1]))+abs(c[i]-c[i+k-1]));
    }
    PRINT(ans);
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& o) {
    out << "(" << o.first << "," << o.second << ")";
    return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& V) {
    for (int i = 0; i < V.size(); i++) {
        out << V[i];
        if (i != V.size() - 1) out << " ";
    }
    return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<vector<T> >& Mat) {
    for (int i = 0; i < Mat.size(); i++) {
        if (i != 0) out << endl;
        out << Mat[i];
    }
    return out;
}
template <class S, class T>
ostream& operator<<(ostream& out, const map<S, T>& mp) {
    out << "{ ";
    for (auto it = mp.begin(); it != mp.end(); it++) {
        out << it->first << ":" << it->second;
        if (mp.size() - 1 != distance(mp.begin(), it)) out << ", ";
    }
    out << " }";
    return out;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template <class Type>
Type solve(Type res = Type()) {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (auto& in : A) cin >> in;
    for (auto& in : B) cin >> in;

    vector<pii> tA(N),tB(N);
    for(int i = 0; i < N;i++){
        tA[i] = make_pair(A[i],i);
        tB[i] = make_pair(B[i],i);
    }

    sort(tA.begin(), tA.end());
    sort(tB.begin(), tB.end());

    for (int i = 0; i < N; i++) {
        if (tA[i].first > tB[i].first) return "No";
    }

    vector<int> pos(N);
    for(int i = 0; i < N-1;i++){
        if(tA[i+1].first <= tB[i].first){
            return "Yes";
        }
        pos[tA[i].second] = tB[i].second;
    }
    pos[tA[N-1].second] = tB[N-1].second;

    int now = 0;
    int T = 1;
    while(pos[now]){
        now = pos[now];
        T++;
    }
    if(T == N){
        return "No";
    }else{
        return "Yes";
    }
    return res;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // solve<ll>(0);
    cout << fixed << setprecision(12) << solve<string>() << endl;
    return 0;
}

Measured memory_bytes: 5836
#include<iostream>
#include<list>

using namespace std;

void solve(int n){
  list <int> s;
  for(int i = 0 ; i < n ; i++ ){
    int a;
    cin >> a;
    s.push_back(a);
  }
  
  int s_max = 0;
  int s_min = 0xFFFF;
  list<int>::iterator s_max_it;
  list<int>::iterator s_min_it;

  for(list<int>::iterator it = s.begin() ; it != s.end() ; it++ ){
    if(*it > s_max){
      s_max = *it;
      s_max_it = it;
    }
    if(*it < s_min){
      s_min = *it;
      s_min_it = it;
    }
  }
  
  s.erase(s_max_it);
  s.erase(s_min_it);

  int sum = 0;
  for(list<int>::iterator it = s.begin() ; it != s.end() ; it++ ){
    sum += *it;
  } 
  cout << sum / (n-2) << endl;
  return;
}

int main(){
  
  while(1){
  
  int n;
  cin >> n;
  
  if(n > 0)
    solve(n);
  else
    break;

  }

  return 0;
}

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


int main(){
  int a,b,c;
  scanf("%d %d",&a,&b);
  if(a>b){
    c=a;
    a=b;
    b=c;
  }
  while(b%a!=0){
    c=a;
    a=b%a;
    b=c;
  }
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++){
    cin >> d.at(i);
  }
  
  n /= 2;
  sort(d.begin(), d.end());
  int a = d.at(n-1);
  int b = d.at(n);
  
  int counta = 0;
  int countb = 0;
  
  for(int i = 0; i < 2 * n; i++){
    if(d.at(i) < a + 1){
      counta++;
    }
    if(d.at(i) >= b){
      countb++;
    }
  }
  
  if(counta == countb){
    cout << b-a << endl;
  }
  else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>K;
    vec a(N);
    rep(i,N) cin>>a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    ll ans = 0;
    rep(i,K) ans += a[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define eps 1e-13
#define PI 3.141592653589793238L
#define inf 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("input.in", "r", stdin); freopen("output.out", "w", stdout)
const int N =100006;
ll fact[N],ifact[N],a[N];
long long int modpow (long long int a, ll mo) {
	ll res = 1;
	ll j=mo-2;
	while (j > 0)
		if (j & 1) {
			res = (res * a) % mo;
			--j;
		}
		else {
			a = (a * a) % mo;
			j >>= 1;
		}
	return res %mo;
}
ll ncr(int i,int j)
{
	ll w=fact[i]*ifact[j];
	w%=mod;
	w=w*ifact[i-j];
	w%=mod;
	return w;
}
int main()
{
//	io_file;
	fact[0]=1;
	ifact[0]=1;
	for(ll i=1;i<N;i++)
	{
		fact[i]=(fact[i-1]*1LL*i)%mod;
		ifact[i]=modpow(fact[i],mod);
	}
	int n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		ans=(ans+(fact[n]*a[i])%mod)%mod;
		a[i]+=a[i-1];a[i]%=mod;
	}
	for(int d=2;d<=n;d++)
	{
		ll z=a[n]-a[d-1]+a[n-d+1]+mod;
		z%=mod;
		ll w=ncr(n,d)*fact[d-1];
		w%=mod;
		w=w*fact[n-d];
		w%=mod;
		w=w*z;
		w%=mod;
		ans=(ans+w)%mod;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 2560
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n;
ll a[100111],A,B,dp[100111];
int main()
{
	getiii(n,A,B);
	if(A>B)swap(A,B);
	for(int i=1;i<=n;i++)geti(a[i]);
	dp[0]=1;a[0]=-B;
	a[n+1]=a[n]+B;
	for(int i=2;i<n;i++)
	{
		if(a[i+1]-a[i-1]<A)
		{
			puts("0");
			return 0;
		}
	}
	n++;
	ll ans=0;
	int it=0,itr=0;
	for(int i=1;i<=n;i++)
	{
		while(itr+1<i&&a[i]-a[itr+1]>=B)itr++;
//		cerr<<i<<":"<<it<<","<<itr<<endl;
		dp[i]=dp[i-1];
		if(it<=itr)
		{
			dp[i]=(dp[i]+dp[itr])%mod;
			if(it>0)dp[i]=(dp[i]-dp[it-1]+mod)%mod;
		}
		if(i>1&&a[i]-a[i-1]<A)it=max(it,i-1);
//		cerr<<dp[i]<<endl;
	}
	cout<<(dp[n]-dp[n-1]+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 1920
using System;
using System.Linq;

namespace abc074_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 0;
            for (int i = 0; i < n; i++)
            {
                ret += Math.Min(x[i], k - x[i]);
            }
            Console.WriteLine(ret * 2);
        }
    }
}

Measured memory_bytes: 13268
import sys
input = sys.stdin.readline
N = int(input())
a = [int(x) for x in input().split()]

def beki(i) :
    t = 0
    while i%2 == 0 :
        t += 1
        i //= 2
    return t

ans = 0
for i in a :
    ans += beki(i)

print(ans)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;

constexpr int MAXN = 5 + 1e5;

int get(int x) {
  int s = 0;
  for (int i = 1;;++i) {
    s += i;
    if (s > x) return i-1;
  }
  assert(false);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  ll n;
  cin >> n;
  int ans = 0;

  for (ll i = 2; i*i <= n; ++i) {
    int c = 0;
    while ((n%i) == 0) {
      ++c;
      n /= i;
    }
    if (c) ans += get(c);
  }
  if (n != 1) ans++;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3652
S = input()

rs = [0] * 13

M = 10**9 + 7

if S[-1] == "?":
    rs[:10] = [1] * 10
else:
    rs[int(S[-1])] = 1

for i in range(1, len(S)):
    nrs = [0] * 13
    c = S[-i - 1]
    if c == "?":
        ns = range(10)
    else:
        ns = [int(c)]
    for n in ns:
        r = (10 ** (i % 6)) * n % 13
        for j in range(13):
            jj = (j + r) % 13
            nrs[jj] = (nrs[jj] + rs[j]) % M
    rs = nrs

# print(rs)
print(rs[5])



Measured memory_bytes: 42988
#include<stdio.h>
 
int main(void){
 
  int i,j;
  int a=0;
 
  char S[10];
  /* 文字を入力 */
  scanf("%s", S);
     for (i = 0;S[i] != '\0';i++);
    if(S[0] != 'A'){
        goto WA;
    }
    else if(i < 4 || i > 10){
        goto WA;
    }
    else if((S[1]>= 'A') && (S[1]<='Z')){
        goto WA;

    }
    else if((S[i-1]>= 'A') && (S[i-1]<='Z')){
        goto WA;

    }
    else{
        for(j = 2;j < i-1; j++){
            if((S[j]>= 'A') && (S[j]<='Z')){
                if(S[j] != 'C'){
                    goto WA;
                }
                else{
                    a = a + 1;
                }
            }
        }
    }
    if(a == 1){
printf("AC");
goto End;
    }
    else goto WA;
WA:
printf("WA");

End:
 
  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0

for i in reversed(range(N)):
    
    for j in reversed(range(2)):
    
        temp = min(A[i + j], B[i])
        ans += temp
        A[i + j] -= temp
        B[i] -= temp
        
print(ans)

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

int main() {
	int n,m;
  cin>>n>>m;
  int h[n];
  int ma[n];
  for(int i=1;i<=n;++i){
    cin>>h[i];
    ma[i]=0;
  }
  

  rep(i,m){
    int a,b;
    cin>>a>>b;
    ma[a]=max(ma[a],h[b]);
    ma[b]=max(ma[b],h[a]);
  }
  int ans=0;
  for(int i=1;i<=n;i++){
  	ans += h[i]>ma[i];
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 4392
import sys
N, M, X=map(int, sys.stdin.readline().rstrip().split())
A = [list(map(int, sys.stdin.readline().rstrip().split())) for i in range(N)]
cost=[]
for i in range(1<<N):	#Bit All Search
	l=[0]*(M+1)			#Initialize Check list
	for j in range(N):
		if((i>>j)&1):	#delete ==1
			l=[l[k]+A[j][k] for k in range(M+1)]
	for k in range(M):
		if l[k+1]<X:
			break
	else:cost.append(l[0])
cost.sort()
print(-1 if cost==[] else cost[0])

Measured memory_bytes: 9240
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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 int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int powMod(int n, int p) {
  int res = 1;
  while (p) {
    if (p & 1) (res *= n) %= MOD;
    (n *= n) %= MOD;
    p >>= 1;
  }
  return res;
}
int invMod(int n) {
  return powMod(n, MOD - 2);
}

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

  map<pair<int, int>, pair<int, int>> m;

  int zero = 0;
  REP(i, N){
    int x, y;
    cin >> x >> y;
    if(x == 0 && y == 0){
      zero++;
      continue;
    }

    if(y < 0 || (y == 0 && x < 0)){
      x *= -1; y *= -1;
    }
    if(x == 0){
      m[{0, 1}].first++;
    }else if(y == 0){
      m[{0, 1}].second++;
    }else{
      int g = gcd(x, y);
      x /= g; y /= g;
      if(x > 0 && y > 0) m[{x, y}].first++;
      else{
        int tmp = x;
        x = y;
        y = -tmp;
        m[{x, y}].second++;
      }
    }
  }

  auto f = [&](pair<int, int> p){
    int a = 0, b = 0;
    if(p.first != 0) a = (int)powMod(2, p.first)-1;
    if(p.second != 0) b = (int)powMod(2, p.second)-1;
    return (a+b+1)%MOD;
  };

  int ans = 1;
  for(auto p : m){
    (ans *= f(p.second)) %= MOD;
  }

  cout << ((ans+zero-1)%MOD+MOD)%MOD << "\n";

  return 0;
}

Measured memory_bytes: 19200
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll n, x, ans = 1;
    cin >> n >> x;
    vi d(n+1, 0);
    repf(i, n){
        ll l; cin >> l;
        d[i] = d[i-1] + l;
        if(d[i] <= x) ans++;
    }
    // repf(i, n+1) d[i] = d[i-1] + l[i-1];
    // auto it = upper_bound(all(d), x);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  string str;
  cin >> str;
  int sum = 0;
  for(int i = 0; i < (int)str.size(); ++i){
    char ch = str[i];

    if (ch == '1') {
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
def bfs(q_list):
    cnt = -1
    while q_list:
        cnt += 1
        new_q_list = []
        for h, w in q_list:
            if not m_list[h][w+1]:
                m_list[h][w+1] = True
                new_q_list.append((h, w+1))
            if not m_list[h+1][w]:
                m_list[h+1][w] = True
                new_q_list.append((h+1, w))
            if not m_list[h][w-1]:
                m_list[h][w-1] = True
                new_q_list.append((h, w-1))
            if not m_list[h-1][w]:
                m_list[h-1][w] = True
                new_q_list.append((h-1, w))
        q_list = new_q_list
    print(cnt)


if __name__ == "__main__":
    h_len, w_len = map(int, input().split())
    m_list = [[True for _ in range(w_len+2)]]
    for _ in range(h_len):
        m_list.append([True] + [s=='#' for s in input()] + [True])
    m_list.append([True for _ in range(w_len+2)])
    q_list = []
    for h, w_list in enumerate(m_list):
        if 0 < h < h_len+1:
            for w, a in enumerate(w_list):
                if 0 < w < w_len + 1 and a:
                    q_list.append((h, w))
    bfs(q_list)


Measured memory_bytes: 106036
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const int MOD = 1e+9+7;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<long long> p, n;
    REP(i, N){
        long long A;
        cin >> A;
        if(A >= 0) p.push_back(A);
        else n.push_back(A);
    }

    sort(p.begin(), p.end());
    sort(n.begin(), n.end());

    int ps = p.size();
    int ns = n.size();
    long long ans = 1;
    if(N == K){
        REP(i, ps) ans = (ans*p[i])%MOD;
        REP(i, ns) ans = (ans*n[i])%MOD;
    }else if(ns == N){
        if(K%2 == 0) REP(i, K) ans = (ans*n[i])%MOD;
        if(K%2 == 1) REP(i, K) ans = (ans*n[N-1-i])%MOD;
    }else{
        int i = ps-1, j = 0;
        if(K%2 == 1){
            ans *= p[i];
            ans %= MOD;
            --i, --K;
        }
        while(K){
            if((0 <= i-1 and j+1 < ns and p[i-1]*p[i] >= n[j]*n[j+1]) or j >= ns-1){
                ans *= p[i-1]*p[i] % MOD; 
                ans %= MOD;
                i -= 2;
            }else{
                ans *= n[j]*n[j+1] % MOD; 
                ans %= MOD;
                j += 2;
            }
            K -= 2;
        }
    }
    cout << (ans+MOD)%MOD << endl;

    return 0;
}

Measured memory_bytes: 5464
#include<iostream>
#include<string>
#include<cmath>
using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  int x = 0;
  int max_v = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'I'){
      x++;
    }
    else {
      x--;
    }
    max_v = max(x, max_v);
  }
  
  cout << max_v << endl;
}
   

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

ll n;

map<int, int> cnt;
map<int, int> acc;

ll ans;

/////////////////////////////////////////////////////////////
map<ll, ll> prime_factorization(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i] += 1;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}
/////////////////////////////////////////////////////////////

int main(void) {
  // Here your code !
  scanf("%lld", &n);

  map<ll, ll> whole;

  for (int i = 1; i <= n; ++i) {
    map<ll, ll> tmp = prime_factorization(i);

    for (auto itr = tmp.begin(); itr != tmp.end(); ++itr) {
      whole[itr->first] += itr->second;
    }
  }

  ll max_ind = 0;

  for (auto itr = whole.begin(); itr != whole.end(); ++itr) {
    cnt[itr->second] += 1;
    max_ind = max(max_ind, itr->second);
  }

  for (int i = max_ind; i >= 0; --i) {
    acc[i] = 0;
  }

  acc[max_ind] = cnt[max_ind];

  for (int i = max_ind - 1; i >= 0; --i) {
    acc[i] = acc[i + 1] + cnt[i];
  }

  ans += acc[74];
  ans += acc[24] * max(0, (acc[2] - 1));
  ans += acc[14] * max(0, (acc[4] - 1));
  ans += acc[4] * max(0, (acc[4] - 1)) * max(0, (acc[2] - 2)) / 2;

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = 0
        for k in range(d):
            t += (X[i][k] - X[j][k]) ** 2
        a = int(t ** (1 / 2))
        if a ** 2 == t:
            ans += 1
print(ans)

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            AC142C();

        }

        private static void AC142C()
        {
            var N = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var list = Enumerable.Range(1, N).ToArray();

            Array.Sort(p, list);

            //string retStr = string.Empty;
            foreach (var v in list)
            {
                Console.Write(v + " ");
            }
            


            //Console.WriteLine();
            Console.ReadKey();

        }

    }
}


Measured memory_bytes: 27352
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  vector<int> a = {1};
  int tmp = 6;
  for (int i = 1; i <= 7; ++i) {
    a.push_back(tmp);
    tmp *= 6;
  }
  tmp = 9;
  for (int i = 1; i<= 6; ++i){
    a.push_back(tmp);
    tmp *= 9;
  }
  sort(a.begin(), a.end());
  vector<int> dp(N + 1, INF);
  dp[0] = 0;
  for (int i = 0; i < N; ++i){
    for (int j = 0; j < (int)a.size(); ++j){
      if (i + a[j] <= N) dp[i + a[j]] = min(dp[i + a[j]], dp[i] + 1);
    }
  }
  cout << dp[N] << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<vector<int>> F(N,vector<int>(10,0)),P(N,vector<int>(11,0));
  REP(i,N){
    REP(j,10)cin>>F[i][j];
  }
  REP(i,N){
    REP(j,11)cin>>P[i][j];
  }
  int ans=-INF;
  for(int mask=1;mask<(1<<10);mask++){
    int sum=0;
    REP(i,N){
      int cnt=0;
      REP(j,10){
        if((mask&(1<<j))&&F[i][j])cnt++;
      }
      sum+=P[i][cnt];
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
}


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

int main() {
  int H, W;
  scanf("%d %d",&H,&W);
  int c[10][10];
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      scanf("%d",&c[i][j]);
    }
  }
  for (int k=0; k<10; k++) {
    for (int i=0; i<10; i++) {
      for (int j=0; j<10; j++) {
        c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
      }
    }
  }
  int A;
  int res=0;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      scanf("%d",&A);
      if (A>=0) {
        res+=c[A][1];
      }
    }
  }
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int A[3]={};
    for(int i=0;i<3;i++){
        scanf("%d",&A[i]);
    }
    int a = A[0]-A[1];
    int b = A[1]-A[2];
    int c = A[0]-A[2];
    if(a<0){
        a = -a;
    }
    if(b<0){
        b = -b;
    }
    if(c<0){
        c = -c;
    }

    int max = 0;
    if(a>max){
        max = a;
    }
    if(b>max){
        max = b;
    }
    if(c>max){
        max = c;
    }
    printf("%d",a+b+c-max);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int N,K,x;
	scanf("%d %d",&N,&K);
	if(K==1)
		printf("0\n");
	else
	{
		x=N%K;
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int a,b;

int main () 
{
	scanf("%d %d",&a,&b);
	while (a!=0||b!=0)
	{
		for (int i=1;i<=a;i++)
		{
			for (int j=1;j<=b;j++)
			{
				if ((i+j)%2==0)
				{
					printf("#");
				} else 
				{
					printf(".");	
				}
			}
			printf("\n");
		}
		scanf("%d %d",&a,&b);
		printf ("\n");	
	}
}


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

bool isSmallAlphabet(char ch) {
  /* a ~ z(ascii) : 97 ~ 122 */
  if('a' <= ch && ch <= 'z') return true;
  else return false;
}

bool isHit(string str) {
  if(str.find("the") != str.npos) return true;
  else if(str.find("this") != str.npos) return true;
  else if(str.find("that") != str.npos) return true;
  else return false;
}

/* ????????¶??????????§£??? */
void CaesarCipher(string _str) {
  
  /* parameter??????????????¢??????????????????????????????????????? */
  for(int parameter = 0; parameter < 26; ++parameter) {
    string str = _str;
    for(int i = 0; i < (int)str.length(); ++i) {
      
      /* ?°?????????¢??????????????????????????? */
      if(isSmallAlphabet(str[i])) {
        str[i] += parameter;
        /* ???????????????????°?????????§???????????£??????*/
        if(!isSmallAlphabet(str[i])) {
          str[i] -= 26;
        }
      }

    }

    /* Find "the" or "this" or "that" */
    if(isHit(str)) {
      cout << str << endl;
    }
  }
}

int main() {
  string str;
  while(getline(cin, str)) {
    CaesarCipher(str);
  }
  return 0;
}

Measured memory_bytes: 3172
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<P> factor(ll n) {
  vector<P> ret;
  ll q = n;
  for (ll d = 2; d * d <= n; d++) {
    if (q % d > 0) continue;
    ll cnt = 0;
    while (q % d == 0) {
      cnt++;
      q /= d;
    }
    ret.push_back(make_pair(d, cnt));
  }
  if (q > 1) ret.push_back(make_pair(q, 1));
  return ret;
}

void solve() {
  ll n; cin >> n;
  vector<P> v = factor(n);
  cout << n << ":";
  for (P vi : v) {
    for (int i = 0; i < vi.second; i++)
      cout << " " << vi.first;
  }
  cout << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}



Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
 
using namespace std ;

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define N 400000+5


int main () 
{
/////////////////////////////////////
    
    fastio; 

    lli n;
    cin>>n;

    pll a[n];

    loopl(i,0,n) cin>>a[i].ss>>a[i].ff;

    sort(a,a+n);

    lli curr = 0;

    loopl(i,0,n)
    {
        curr += a[i].ss;
        if(curr > a[i].ff)
        {
            cout<<"No";
            return 0;
        }
    }

    cout<<"Yes";

}

Measured memory_bytes: 3328
#include <stdio.h>
static int n, x;
int main(void) {
    int i, j, k, sum;
    while (1) {
        scanf("%d%d", &n, &x);
        if (n == 0 && x == 0) break;
        sum = 0;
        for (i = 1; i <= n - 2; ++i)
            for (j = i + 1; j <= n - 1; ++j)
                for (k = j + 1; k <= n; ++k)
                    if (i + j + k == x) ++sum;
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 600
import math

X = int(input())
sqrtX = math.floor(math.sqrt(X))
ans1 = sqrtX * sqrtX

# 解候補
anslist = [2**3, 2**5, 2**7, 2**9, 3**3, 3**5, 3**7, 5**3, 6**3, 7**3, 10**3]
ans2 = 0
for num in anslist:
    if num <= X and num > ans1: ans2 = num

print(max(ans1,ans2))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC171E()
{
	int N;
	cin >> N;
	vi a(N);
	for (auto& x : a)
		cin >> x;

	int y = 0;
	for (auto& x : a)
		y ^= x;
	for (auto& x : a)
		cout << (y ^ x) << ' ';
	cout << endl;
}


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

Measured memory_bytes: 4044
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

class CReplacingInteger {
public:
	void solve(std::istream& in, std::ostream& out) {
    int n,k;
    in >> n >> k;
    out << min(abs(n % k - k), n % k) << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);
	CReplacingInteger solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main()
{
   long long x, y;
   cin >> x >> y;

   int count = 1;
   for (;;) {
      if (x*2 > y) {
         break;
      } else {
         x *= 2;
         count++;
      }
   }

   printf("%d\n", count);

   return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
long long a, b, c;
int main()
{
	scanf("%lld%lld%lld", &a, &b, &c);
	if (!(a & b & c & 1))
		puts("0");
	else
		printf("%lld\n", std::min(std::min(a * b, a * c), b * c));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

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


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

    vector<int> d(N);
    REP(i,N) cin >> d[i];

    sort(ALL(d));

    if(d[N/2-1]==d[N/2]){
    	cout << 0 << endl;
    	return 0;
    }



    int ans=0;

    ans=d[N/2]-d[N/2-1];


	cout << ans << endl;

}



Measured memory_bytes: 640
#入力
N=int(input())
A = [int(x) for x in input().split()]

ans = [0]*3
answer=1
for i in range(N):
    count=0
    if (A[i] == ans[0]):
        count+=1
    if (A[i] == ans[1]):
        count+=1
    if (A[i] == ans[2]):
        count+=1
    answer*=count
    answer %= 1000000007

    if(A[i] == ans[0]):
        ans[0]+=1
    elif(A[i] == ans[1]):
        ans[1]+=1
    elif(A[i] == ans[2]):
        ans[2]+=1

print(answer)

Measured memory_bytes: 13964
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

typedef long long ll;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

vector <ll> as, idx;
set <ll> st;

void solve(void){
    int N;
    cin >> N;

    as.resize(N), idx.resize(N);

    rep(N, i) {
        cin >> as[i];
        idx[as[i]-1] = i;
    }

    st.insert(-1LL);
    st.insert(N);

    ll ans = 0LL;

    rep(N, i) {
        ll x = idx[i];
        set<ll>::iterator it = st.lower_bound(x);
        ans += (ll)(i+1)*(*(it)-x)*(x-*(--it));
        st.insert(x);
    }

    cout << ans << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  string s;
  bool flag = true;
  cin >> s;
  for (int i = 0; i < s.length(); i++){
    if (i % 2 == 0){
      if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D'){
        continue;
      }else{
        flag = false;
        break;
      }
    }else{
      if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D'){
        continue;
      }else{
        flag = false;
        break;
      }
    }
  }
  if (flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=998244353;
const int size=3e5;
const int inf=1e9;
long fact[300000];
void calc(int n){
	fact[0] = 1;
	rep(i,1,n){
		fact[i] = (fact[i-1] * i) % mod;
	}
	return;
}
long modcomb(long n,long r){//nCr mod p
	if(n < r) return 0;
	long x = (fact[n-r] * fact[r]) % mod;
	long res = 1; int i = 0;
	while( (mod-2) >= (1<<i) ){
		if( (mod-2) & (1<<i) ) (res *= x) %= mod;
		i++; x = x * x % mod;
	}
    return (res * fact[n]) % mod;
}
int main(){
	long N,M,K; cin>>N>>M>>K;
    if(M == 1){
        if(K == N - 1) cout<<1<<endl;
        else cout<<0<<endl;
        return 0;
    }
    calc(300000);
	long t = M;
    for(long i = 0; i < N-K-1; i++) (t *= M-1) %= mod;
    long ans = 0;
	for(long i = K; i >= 0; i--){
		(ans += (t * modcomb(N - 1, i)) % mod) %= mod;
        (t *= M-1) %= mod;
	}cout<<ans<<endl;
}

Measured memory_bytes: 5956
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int n, h, w;
  cin >> n >> h >> w;
  cout << (n + 1 - h) * (n + 1 - w) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,m,k,ans=INF;
char c[15][1005];
int cnt[15];
int num(int x)
{
	int y=x,res=0,pre,cnt2[15];
	memset(cnt,0,sizeof(cnt));
	while(y)
	{
		res+=y%2;
		y/=2;
	}
	forn(j,m)
	{
		y=x*2;
		pre=0;
		bool ok=1;
		forn(i,n)cnt2[i]=cnt[i];
		forn(i,n)
		{
			if(y%2)pre++;
			if(c[i][j]=='1')cnt2[pre]++;
			if(cnt2[pre]>k)ok=0;
			y/=2;
		}
		y=x*2;
		pre=0;
		if(!ok)
		{
			memset(cnt,0,sizeof(cnt));
			res++;
		}
		forn(i,n)
		{
			if(y%2)pre++;
			if(c[i][j]=='1')cnt[pre]++;
			y/=2;
		}
//		forn(i,pre+1)cout<<cnt[i]<<' ';
//		cout<<endl;
		forn(i,n)if(cnt[i]>k)return INF;
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>k;
	forn(i,n)cin>>c[i];
	forn(i,1<<(n-1))
		ans=min(ans,num(i));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int fe(int n){return n/2;}
int fo(int n){return 3*n+1;}

int main(void){
    int s,ans=0;
    cin>>s;
    VI a(10000010);
    a[0]=s;
    for(int i=1;i<1000000;i++){
        if(a[i-1]%2==0)a[i]=fe(a[i-1]);
        else a[i]=fo(a[i-1]);
        rep(j,i){
            if(a[i]==a[j]){
                ans=i+1;
                break;
            }
        }
        if(ans!=0)break;
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 39296
#include <iostream>
#include <atcoder/dsu>

using namespace std;
using namespace atcoder;

int main(int argc, char *argv[])
{
  int n,q; cin >> n >> q;
  dsu d(n);
  while(q-- > 0) {
    int t,u,v; cin >> t >> u >> v;
    if(t == 0) {
      d.merge(u, v);
    }
    else {
      cout << (d.same(u, v) ? 1 : 0) << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 3532
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> ve;
bool ary[100010]={};
int main(){
	int N,hog,cnt,res;
	bool b;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>hog;
		if(hog==1) ary[i]=true;
	}
	b=ary[0];cnt=1;
	for(int i=1;i<N;i++){
		if(b==ary[i]){
			ve.push_back(cnt);
			cnt=1;
		}
		else{
			b=ary[i];
			cnt++;
		}
	}
	ve.push_back(cnt);
	res=0;
	if(ve.size()>=3)for(int i=0;i<ve.size()-2;i++){
		res=max(ve[i]+ve[i+1]+ve[i+2],res);
	}
	else if(ve.size()==2) res=ve[0]+ve[1];
	else res=ve[0];
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1532
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long a, b;
	while (cin >> a >> b) {
		long long gcd;
		long long c = max(a, b);
		long long d = min(a, b);
		while (true) {
			if (c % d == 0) {
				gcd = d;
				goto C;
			}
			else {
				c -= d;
				if (c <= d) {
					swap(c, d);
				}
			}
		}
	C:
		cout << gcd  << endl;
	}
}

Measured memory_bytes: 3100
def powmod(b,r,mod)
  a = 1
  while r > 0
    if r%2 == 1
      a = a * b % mod
    end
    b = b * b % mod
    r /= 2
  end
  a
end

Mod = 10**9+7
N,A,B,C,D = `dd`.split.map &:to_i

$factor = [1]
(1..N).each{ |n| $factor << $factor[-1] * n % Mod }
$invfac = $factor.map{ |f| powmod(f, Mod-2, Mod) }

dp = (0..B).map{ Array.new(N+1, 0) }
dp[A-1][0] = $factor[N]

(A..B).each{ |i|
  invf = $invfac[i]
  dpi = dp[i]
  dpii = dp[i-1]
  (0..N).each{ |m|
    #p "(i,m) = (#{i},#{m})"
    s = dpii[m]
    f = 1
    (1..D).each{ |x|
      f = (f * invf) % Mod
      next if x < C
      mm = m - x*i
      break if mm < 0
      #p "(#{i},#{m}) <- (#{i-1},#{mm}): Fi = #{x}"
      s = (s + dpii[mm] * f * $invfac[x] % Mod) % Mod
    }
    dpi[m] = s
  }
}
p dp[B][N]


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	int r, d, x;
  cin >> r >> d >> x;
  for(int i = 0; i < 10; ++i)
  {
    cout << (x = r * x - d) << endl;
  }
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 1e5;
const int INF = 1e9;
int a[MXN+5];
ll dp[MXN+5];
int N;

ll rec(int pos){

    if(pos==N) return 0;
    if(dp[pos]!=-1) return dp[pos];
    ll ret = INF;
    for(int i=1; i<=2; i++){
        int next = pos + i;
        if(next<=N){
            ret = min( ret , (ll) rec(next) + abs(a[next]-a[pos]) );
        }
    }

    return dp[pos]=ret;
}

void solve(){

    cin>>N;
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=N; i++) cin>>a[i];
    cout<< rec(1) << "\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

Measured memory_bytes: 9480