akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int r,c,n;
pii s[125252], t[125252];
set<pll> S;

ll onedge(pii p){
  int x = p.first, y = p.second;
  if(x==0){
    return y;
  }else if(y==c){
    return c+x;
  }else if(x==r){
    return c+r+(c-y);
  }else if(y==0){
    return c+r+c+(r-x);
  }else{
    return -1;
  }
}

int main(){
  scanf("%d%d%d",&r,&c,&n);
  REP(i,n){
    int x,y;
    scanf("%d%d",&x,&y);
    s[i] = pii(x,y);
    scanf("%d%d",&x,&y);
    t[i] = pii(x,y);
  }
  REP(i,n){
    ll sp=onedge(s[i]);
    ll tp=onedge(t[i]);
    if(sp>=0 && tp>=0){
      S.insert(pll(sp,i));
      S.insert(pll(tp,i));
    }
  }
  if(S.size()==0){
    puts("YES");
    return 0;
  }
  auto it = S.begin();
  queue<int> Q;
  while(true){
    int ida = it->second;
    it++;
    if(it==S.end()){
      it = S.begin();
    }
    int idb = it->second;
    if(ida==idb){
      Q.push(ida);
    }
    if(it==S.begin())break;
  }
  while(Q.size()){
    int id = Q.front(); Q.pop();
    ll sp = onedge(s[id]);
    ll tp = onedge(t[id]);
    if(!S.count(pll(sp,id)))continue;
    S.erase(pll(sp,id));
    S.erase(pll(tp,id));
    if(sp>tp)swap(sp,tp);
    if(S.size()==0)break;
    auto it1 = S.upper_bound(pll(tp,id));
    if(it1==S.end())it1 = S.begin();
    auto it2 = S.lower_bound(pll(sp,id));
    if(it2==S.begin())it2 = S.end();
    it2--;
    if(it1->second == it2->second){
      Q.push(it1->second);
    }
  }
  puts(S.size()==0 ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
    if(flg) {
        cout << hoge << endl;
        exit(0);
    }
}
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
vl Z_algorithm(string S) {
    ll c = 0, n = S.size();
    vl Z(n, 0);
    for(int i = 1; i < n; i++) {
        int l = i - c;
        //今着目してる部分が赤下線の左端から何個分離れているかをlに入れる。
        if(i + Z[l] < c + Z[c]) {
            //この条件を満たすのは、「青下線が赤下線に収まる」。
            //この時、すでに計算されてるなのでそれを流用する。
            Z[i] = Z[l];
        } else {
            //この条件を満たすのは、「赤下線から青下線が溢れる」or「赤下線と青下線の共通部分がない」。
            int j = max(0LL, c + Z[c] - i);
            while(i + j < n && S[j] == S[i + j])
                j++;

            Z[i] = j;
            c = i;
        }
    }
    Z[0] = n;
    return Z;
}
vl Z[MAX_N];
int main() {
    cin >> n;
    string S;
    cin >> S;

    rep(i, n) {
        Z[i] = Z_algorithm(S.substr(i));
        rep(j, n - i) { ans = max(ans, min(Z[i][j], j)); }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 109696
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  long long n;
  long long b;
  long long r;
  cin >> n >> b >> r;
  if (b == 0) {
    cout << 0 << endl;
    return 0;
  }
  // cout << n << endl;
  // cout << b << endl;
  // cout << r << endl;

  if (n <= b) {
    cout << n << endl;
    return 0;
  }

  long long counts = n / (b+r);
  long long ans = 0;
  ans = b * counts;
  long long rem = n % (b+r);
  ans += min(rem, b);
  cout << ans << endl;
  return 0;
}

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

constexpr int MAX = 200005;
int width[MAX];
int height[MAX];

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

	int n, w, h;
	cin >> n >> w >> h;

	w <<= 1;
	h <<= 1;

	for(int i = 0; i < n; ++i) {
		int x, y, p;
		cin >> x >> y >> p;

		++width[max(0, 2 * (x - p))];
		--width[min(w, 2 * (x + p)) + 1];
		++height[max(0, 2 * (y - p))];
		--height[min(h, 2 * (y + p)) + 1];
	}

	bool f1 = true;
	bool f2 = true;

	int current = 0;
	for(int x = 0; x <= w; ++x) {
		current += width[x];
		if (current == 0) {
			f1 = false;
			break;
		}
	}

	current = 0;
	for(int y = 0; y <= h; ++y) {
		current += height[y];
		if (current == 0) {
			f2 = false;
			break;
		}
	}
	cout << (f1 || f2 ? "Yes" : "No") << endl;

	return EXIT_SUCCESS;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    string s;
    cin>>s;
    cout<<count(s.begin(),s.end(),'2')<<endl;
    return 0;
}

Measured memory_bytes: 3580
from fractions import gcd

a,b,c,d = [int(i) for i in input().split()]

lcmcd = c * d / gcd(c, d)
lcmcd = int(lcmcd)

numb = b - (b//c) - (b//d) + (b//lcmcd)
numa = a-1 - ((a-1)//c) - ((a-1)//d) + ((a-1)//lcmcd)

print(numb-numa)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c - max(a, max(b, c));
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  std::string N;

  std::cin >> N;

  std::cout << (N.find('9') != std::string::npos ? "Yes" : "No") << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
// const int INF=4e18+10;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}


void solve()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        if(x%2==0 &&(x%3!=0 && x%5!=0))
        {
             cout<<"DENIED"<<endl;
             return;
        }
    }
            cout<<"APPROVED"<<endl;
    return;
}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353, N = 1 << 20;

long long modpow(int a, int b) {
	long long ans = 1;
	for (long long aa = a; b; b >>= 1, aa = aa * aa % MOD) {
		if (b & 1) ans = ans * aa % MOD;
	}
	return ans;
}

long long modinv (int b) {
	return modpow(b, MOD - 2);
}

vector <int> lastPrime (int n) {
	vector <int> ans(n + 1,0);
	for (int i = 2; i <= n; ++i) {
		if (ans[i] == 0) {
			for (int j = i; j <= n; j += i) {
				ans[j] = i;
			}
		}
	}
	return ans;
}
 
vector <int> make_mobius (int n) {
	vector <int> LPrime = lastPrime(n), mobius(n + 1);
	mobius[1] = 1;
	for (int i = 2; i <= n; ++i) {
		if (LPrime[i] == LPrime[i / LPrime[i]]) mobius[i] = 0;
		else mobius[i] = mobius[i / LPrime[i]] * -1;
	}
	return mobius;
}

int main () {
	vector <int> mu = make_mobius(N);
	int n, tmp;
	cin >> n;
	vector <int> c(N + 1, 0);
	vector <long long> summ(N + 1, 0);
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
        cin >> tmp;
        c[tmp]++;
        ans += (MOD - tmp);
    }
    ans %= MOD;
	for (int i = 1; i <= N; ++i) {
		for (int j = i; j <= N; j += i) {
			summ[i] += 1ll * c[j] * j;
		}
		summ[i] %= MOD;
		summ[i] = summ[i] * summ[i] % MOD;
	}
	for (int i = 1; i <= N; ++i) {
	    long long tmp = 0;
		for (int j = 1; j * i <= N; j++) {
			(tmp += summ[i * j] * mu[j]) %= MOD;
		}
      	(ans += tmp * modinv(i) % MOD) %= MOD;
	}
	if (ans < 0) ans += MOD;
	cout << ans * modinv(2) % MOD << endl;
}

Measured memory_bytes: 16764
#include<stdio.h>
#include<string.h>
int main()
{
	int n,m,v,i,j;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		char a[n+2][m+2];
		v=(n+2)*(m+2);
		memset(a,'#',sizeof(char)*v);
		for(i=1;i<n+1;i++)
		{
			for(j=1;j<m+1;j++)
			{
				scanf("\n%c",&a[i][j]);
			}
		}
		for(i=0;i<n+2;i++)
		{
			for(j=0;j<m+2;j++)
			{
				printf("%c",a[i][j]);
			}
			printf("\n");
		}
	}
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int t[26];
#define DIV 4
ll dp[10001];
int main(void) {
	int n, v, f = 0;
	cin >> n;
	rep(i, 0, n) {
		cin >> v;
		if (v % 2)f = 1;
	}
	puts(f ? "first" : "second");
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

vector<int> dist;
vector<bool> neg;
void bellman_ford(vector<vector<P>>& edge, int n, int s){
    dist = vector<int>(n + 1, INF);
    neg = vector<bool>(n + 1, false);
    dist[s] = 0;
    for(int i = 0; i < n; i++){
        for(int v = 1; v <= n; v++){
            for(int k = 0; k < (int)edge[v].size(); k++){
                P p = edge[v][k];
                if(neg[v]){
                    neg[p.first] = true;
                }
                if(dist[v] != INF && dist[p.first] > dist[v] + p.second){
                    dist[p.first] = dist[v] + p.second;
                    if(i == n - 1) neg[p.first] = true;
                }
            }
        }
    }
}

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

    int n, m;
    cin >> n >> m;
    auto edge = initVec2<P>(n + 1, 0);
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        edge[a].emplace_back(b, -c);
    }

    bellman_ford(edge, n, 1);
    if(neg[n]){
        cout << "inf" << endl;
    }else{
        cout << -dist[n] << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
//		cout<<a%5<<endl;
		if(a%2==0&&a%3>0&&a%5>0)
		{
			cout<<"DENIED"<<endl;
			return 0;
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    map<int, int>m;
    for (int i=0; i < K; i++) {
        int d;
        cin >> d;
        for (int j=0; j < d; j++) {
            int num;
            cin >> num;
            m[num] = 1;
        }
    }

    int sum = 0;
    for (int i=1; i <=N; i++) {
        if (m.count(i) == 0) {
            sum += 1;
        }
    }

    cout << sum << endl;

    return 0;
}

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

long long gcd(long long A,long long B){
    if (A % B == 0) return B;
    return gcd(B, A % B);
}

void solve(long long A,long long B,long long C,long long D){
    long long ans_a = 0;
    long long ans_b = 0;
    ans_a = (A-1) - ((A-1) / C) - ((A-1) / D);
    ans_b = B - (B / C) - (B / D);
    ans_a += (A-1) / (C * D / gcd(C,D));
    ans_b += B / (C * D / gcd(C,D));
    cout << ans_b - ans_a<< endl;
    
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;

int n, x;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> n >> x;
    vector<ll> a(n, 0); for(int i = 0; i < n; i++) cin >> a[i];
    ll ret = 0;
    
    for(int i = 0; i < n - 1; i++)
    {
        auto sum = a[i] + a[i+1];
        if(sum <= x) continue;
        
        ll diff = sum - x;
        
        ll remove = min(a[i+1], diff);
        ret += remove; a[i+1] -= remove; diff -= remove;
        
        
        ret += diff;
    }
    
    
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 1024
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,m;
	cin>>n>>m;
	ll c=0,q=0;
	int mp[n+1] = {0};
	rep(i,0,m){
		ll p;
		string s;
		cin>>p>>s;
		if(s == "AC"){
			if(mp[p] != -1){
				c++;
				q += mp[p];
				mp[p] = -1;
			}
		}
		else{
			if(mp[p] != -1){
				mp[p]++;
			}
		}
	}
	cout<<c<<" "<<q<<endl;
    return 0;
}

Measured memory_bytes: 640
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
n = int(input())

A = [[0,0,0],[0,0,0],[0,0,0]]

for _ in range(n):
    b = int(input())
    if b in A1:
        tmp = A1.index(b)
        A[0][tmp] = 1
    elif b in A2:
        tmp = A2.index(b)
        A[1][tmp] = 1
    elif b in A3:
        tmp = A3.index(b)
        A[2][tmp] = 1

if A[0][0] + A[0][1] + A[0][2] == 3 or A[1][0] + A[1][1] + A[1][2] == 3 or A[2][0] + A[2][1] + A[2][2] == 3:
    print('Yes')
elif A[0][0] + A[1][0] + A[2][0] == 3 or A[0][1] + A[1][1] + A[2][1] == 3 or A[0][2] + A[1][2] + A[2][2] == 3:
    print('Yes')
elif A[0][0] + A[1][1] + A[2][2] == 3 or A[0][2] + A[1][1] + A[2][0] == 3:
    print('Yes')
else:
    print('No')

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

using namespace std;

long long inf=1000000007;

int main(){
	long long l,r,d;
	cin>>l>>r>>d;
	long long ans=0;
	for(long long i=l;i<=r;i++){
		if(i%d==0) ans++;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3548
fun lower_bound(v: LongArray, num: Long): Int {
    var l = 0
    var r = v.size
    while(r - l > 1){
        val mid = (l + r) / 2
        if(v[mid] < num)l = mid
        else r = mid
    }
    if(v[l] < num)l++
    return l
}

fun main(args: Array<String>) {
    val (a, b, q) = readLine()!!.split(" ").map{it.toInt()}
    val s = LongArray(a)
    val t = LongArray(b)
    val x = LongArray(q)
    for(i in 0 until a)s[i] = readLine()!!.toLong()
    for(i in 0 until b)t[i] = readLine()!!.toLong()
    for(i in 0 until q)x[i] = readLine()!!.toLong()

    for(i in 0 until q){
        var ans = 1000000000000000L
        val A = lower_bound(s, x[i])
        val B = lower_bound(t, x[i])
        if(A < s.size && B < t.size) {
            ans = Math.min(ans, Math.max(s[A], t[B]) - x[i])
        //    println("   ${Math.max(s[A], t[B]) - x[i]}")
        }
        if(A < s.size && B != 0){
            ans = Math.min(ans, s[A] - t[B-1] + Math.min(s[A] - x[i], x[i] - t[B-1]))
        //    println("   ${s[A] - t[B-1] + Math.min(s[A] - x[i], x[i] - t[B-1])}")
        }
        if(B < t.size && A != 0){
            ans = Math.min(ans, t[B] - s[A-1] + Math.min(t[B] - x[i], x[i] - s[A-1]))
        //    println("   ${t[B] - s[A-1] + Math.min(t[B] - x[i], x[i] - s[A-1])}")
        }
        if(A != 0 && B != 0){
            ans = Math.min(ans, x[i] - Math.min(s[A-1], t[B-1]))
        //    println("   ${x[i] - Math.min(s[A-1], t[B-1])}")
        }

        println(ans)
    }
}

Measured memory_bytes: 55252
#include <iostream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  int N, K;
  scanf("%d%d", &N, &K);

  int A[N];
  int min_index = 0;
  REP(i, N) {
    scanf("%d", &A[i]);
    if (A[i] == 1)
      min_index = i;
  }
  OUT((N-1+K-2) / (K-1));

  return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static String[] input;
    public static void main(String[] args) {
        while(read()){
            solve();
        }
    }
    static boolean read(){
        if(!sc.hasNext())return false;
        input = sc.nextLine().split(" ");
        return true;
    }
    static void solve(){
        boolean found = false;
        for(int k = 0; k < 26; k++){
            for(int i = 0; i < input.length; i++){
                char[] word = input[i].toCharArray();
                for(int j = 0; j < word.length; j++){
                    if(Character.isLowerCase(word[j])){
                        word[j] = (char)((word[j] - 'a' + 1)%26 +'a');
                    }
                }
                input[i] = new String(word);
                if(input[i].equals("the") || input[i].equals("this") || input[i].equals("that"))found = true;
            }
            if(found)break;
        }
        for(int i = 0; i < input.length-1; i++){
            System.out.print(input[i] + " ");
        }
        System.out.println(input[input.length-1]);
    }
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	int64_t X, A, B;
	if (scanf("%" PRId64 "%" PRId64 "%" PRId64, &X, &A, &B) != 3) return 1;
	if (B <= A) puts("delicious");
	else if (B <= A + X) puts("safe");
	else puts("dangerous");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
     
     
typedef long long ll;
typedef vector <int> vi;
typedef pair <int,int> pi;
typedef tuple <int,int,int> ti;

#define forn(i,a,n) for(int i = a; i < n ; i++)
#define mem(str,a) memset(str, a, sizeof(str));
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(nullptr)
const int MOD = 1e9+7, N = 1e7 + 10, E = 1e-9;
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//vector <int> show;
//for (auto x : show)
//   cout << x << " ";
getline(cin,s);


*/

int main() {
    string s;
    cin >> s;
    int a = 0, z = s.size();
    forn(i,0,s.size()){
        if(s[i] == 'A') {
            a = i;
            break;
        }
    }
    for(int i = s.size()-1; i > 0; i--) {
        if(s[i] == 'Z') {
            z = i;
            break;
        }
    }
    cout << z-a+1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;
  cin >> n >> m;
  ll s[n+1]; s[0]=0;
  ll a[n];
  multiset<ll> ms;
  set<ll> se;
  ms.insert(0);
  se.insert(0);
  rep(i,n){
    cin >> a[i];
    s[i+1]=s[i]+a[i];
    ms.insert(s[i+1]%m);
    se.insert(s[i+1]%m);
  }
  ll ans=0;
  for(auto i:se){
    ll cou = ms.count(i);
    ans += cou * (cou-1)/2;
  }
  cout << ans << endl;
  //  cout << endl << endl;
  //  cout << static_cast<double>(clock()) / CLOCKS_PER_SEC << "s"<<endl;
  return 0;


}


Measured memory_bytes: 9472
package main

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

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

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

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

func main() {
	sc.Split(bufio.ScanWords)
	N, Y := nextInt(), nextInt()

	fmt.Printf("%s\n", ABC085C(N, Y))
}

// ABC085C ...
func ABC085C(N, Y int) string {
	for i := 0; i <= Y/10000; i++ {
		for j := 0; j <= Y/5000 && i+j <= N; j++ {
			k := N - i - j
			y := i*10000 + j*5000 + k*1000
			if y == Y {
				return strconv.Itoa(i) + " " + strconv.Itoa(j) + " " + strconv.Itoa(k)
			}
		}
	}

	return "-1 -1 -1"
}


Measured memory_bytes: 1776
import math 
c = int(input())
a = 90
x,y = 0,0
e = 0.000000001

k = 1
x = math.sin(math.radians(a))
y = math.cos(math.radians(a))
while (x < -e or x > e or y < -e or y > e):
  a += c
  x += math.sin(math.radians(a))
  y += math.cos(math.radians(a))
  k += 1
print(k)

Measured memory_bytes: 62392
#include <iostream>
#include <string>
#include <algorithm>
#define llint long long

using namespace std;

llint n, a, b;

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

	cin >> n >> a >> b;
	llint ans = n/(a+b) * a;
	n %= a+b;
	ans += min(n, a);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
using namespace std;
int main()
{
    ll n,i;
    string s,t;
    cin>>n>>s>>t;
    for(i=0;i<n;i++){
    cout<<s[i]<<t[i];
    }
    cout<<endl;






    return 0;
}





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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    while(true) {
        C = C - B;
        A = A - D;
        if (C <= 0) {
            printf("Yes");
            return 0;
        } else if (A <= 0) {
            printf("No");
            return 0;
        }
    }
}

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

class task {
public:
	void input(string n, int time) {
		name = n;
		endTime = time;
	}

	int  timeReduce(int q) {
		endTime -= q;
		return endTime;
	}

	string getName() {
		return name;
	}
	
//	void setName(char n[]) {
////		name = n;
//		strcpy(name.c_str, n);
//	}

	int getTime() {
		return endTime;
	}

	void setTime(int t) {
		endTime = t;
	}

//private:
	string name;
	int endTime;
};

class queue {
public:
	queue(int h, int t) {
		m_iHead = h;
		m_iTail = t;
	}

	bool isEmpty() {
		return m_iHead == m_iTail;
	}

	bool isFull() {
		return m_iHead == (m_iTail + 1) % m_iMAX;
	}

	void enqueue(task x) {
		if (isFull()) return;
		Q[m_iTail] = x;
		if (m_iTail + 1 == m_iMAX) {
			m_iTail = 0;
		}
		else {
			m_iTail++;
		}
	}

	 task dequeue() {
		 task t;
		 if (isEmpty()) return t;
		t = Q[m_iHead];
		if (m_iHead + 1 == m_iMAX) {
			m_iHead = 0;
		}
		else {
			m_iHead++;
		}
		return t;
	}

	 task * getQ() {
		 return Q;
	 }

private:
	task Q[100000];
	int m_iHead;
	int m_iTail;
	const int m_iMAX = 100000;
};

int main() {
	int proces; //??????????????°
	int quwontum;
	int elaps = 0;

	cin >> proces;
	cin >> quwontum;
	queue  *pQ = new queue(0, proces);
	for (int i = 0; i < proces; i++) {
		//string sTemp;
		//int iTemp;
		cin >> pQ->getQ()[i].name;
		cin >> pQ->getQ()[i].endTime;
		//pQ->getQ()[i]->name;
		//pQ->getQ()[i]->endTime;
	}

	while (!pQ->isEmpty()) {
		task t = pQ->dequeue();
		int eT = quwontum < t.endTime ? quwontum : t.endTime;
		t.endTime -= eT;
		elaps += eT;
		if (t.endTime > 0) {
			pQ->enqueue(t);
		}
		else {
			cout << t.name << " " << elaps << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 6976
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 998244353
#define M 220000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
vi dp(1000,-1);
int f(int a){
	if(dp[a]+1)return dp[a];
	return dp[a]=powmod(fact[a],MOD-2,MOD);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m;
	cin>>n>>m;
	vvi dp(100,vi(n));
	rep(i,n)cin>>dp[0][i],dp[0][i]--;

	rep(i,99)rep(j,n)dp[i+1][j]=dp[i][dp[i][j]];
	int t=0;
	rep(i,100)if(1ll<<i&m){
		m-=1ll<<i;
		t=dp[i][t];
	}
	cout<<t+1<<endl;
}


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

using namespace std;

int main(){
  long long n, C, d[39][39], c[509][509];
  cin >> n >> C;
  for(int i=1;i<=C;i++){
    for(int j=1;j<=C;j++){
      cin >> d[i][j];
    }
  } 
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      cin >> c[i][j];
    }
  }
  long long cost[4][39];
  memset(cost, 0, sizeof(cost));
  for(int k=1;k<=C;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        cost[(i+j)%3][k]+=d[c[i][j]][k];
      }
    }
  }
  long long mn=1e16;
  for(int i=1;i<=C;i++){
    for(int j=1;j<=C;j++){
      if(i==j)continue;
      for(int k=1;k<=C;k++){
        if(k==i||k==j)continue;
        mn = min(mn, cost[0][i]+cost[1][j]+cost[2][k]);
      }
    }
  }
  cout << mn << endl;
}



Measured memory_bytes: 5608
#include <stdio.h>

int main(void) {
	int n,i,c,f,d;
	while(scanf("%d",&n),n!=0){
		c = 0;f = 0;
		for(i = 1;i <= n;i++){
			scanf("%d",&d);
			if(d != 0){c++;}
			if(d >= 2){f = 1;}
		}
		if(f == 0){printf("NA\n");}
		else{printf("%d\n",c+1);}
	}
	return 0;
}

Measured memory_bytes: 612
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n = I()
    a = LI()
    d = dict()
    for i in range(1,n+1):
        d[i]=0
    for i in range(len(a)):
        d[a[i]]+=1

    for i in d:
        print(d[i])

if __name__ == "__main__":
    main()

Measured memory_bytes: 40540
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
int a,b;
cin>>a>>b;
if(a==1) a+=13;
if(b==1) b+=13;

if(a>b) cout<<"Alice"<<endl;
else if(a<b) cout<<"Bob"<<endl;
else cout<<"Draw"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

class Dice{
public:
    Dice(int labels[]);
    void rotate(char);
    void rotate(string);
    int top(){return t;};

private:
    int t, s, e, w, n, b;
    void rotate(int &direction, int &opposite);
};

Dice::Dice(int labels[]){
    t = labels[0];
    s = labels[1];
    e = labels[2];
    w = labels[3];
    n = labels[4];
    b = labels[5];
}

void Dice::rotate(char direction){
    if(direction == 'N') rotate(n, s);
    if(direction == 'E') rotate(e, w);
    if(direction == 'S') rotate(s, n);
    if(direction == 'W') rotate(w, e);
}

void Dice::rotate(int &direction, int &opposite){
    int old = direction;
    direction = t;
    t = opposite;
    opposite = b;
    b = old;
}

void Dice::rotate(string directions){
    for(auto ch : directions) rotate(ch);
}

int main(){
    int labels[6] = {};
    for(auto &face : labels){
        cin >> face;
    }
    Dice dice(labels);
    string directions;
    cin >> directions;
    dice.rotate(directions);
    cout << dice.top() << endl;
}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

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

    vector<int> cnt(N + 1, 0);
    for(int i = 0; i < N; i++){
        cnt[A[i]]++;
        cnt[B[i]]++;
    }

    for(int i = 1; i <= N; i++){
        if(cnt[i] > N){
            cout << "No" << endl;
            return 0;
        }
    }

    reverse(B.begin(), B.end());

    vector<bool> same(N);
    int sameNum = -1;
    for(int i = 0; i < N; i++){
        if(A[i] == B[i]){
            same[i] = true;
            sameNum = A[i];
        }
        else{
            same[i] = false;
        }
    }

    int diffIndex = 0;
    int sameIndex = 0;
    while(sameIndex < N && diffIndex < N){
        while(sameIndex < N && !same[sameIndex]){
            sameIndex++;
        }
        if(sameIndex == N){
            break;
        }

        while(diffIndex < N && (same[diffIndex] || A[diffIndex] == sameNum || B[diffIndex] == sameNum)){
            diffIndex++;
        }
        if(diffIndex == N){
            break;
        }

        swap(B[sameIndex], B[diffIndex]);
        sameIndex++;
        diffIndex++;
    }

    cout << "Yes" << endl;
    for(int i = 0; i < N; i++){
        cout << B[i];
        if(i == N - 1){
            cout << endl;
        }
        else{
            cout << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 5628
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int A, B, M, ans, a[100009], b[100009], x, y, c;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> A >> B >> M;
	int tmp = 0;
	for (int i = 0; i < A; i++) {
		cin >> a[i];
		if (a[i] < a[tmp]) tmp = i;
	}
	ans += a[tmp];
	tmp = 0;
	for (int i = 0; i < B; i++) {
		cin >> b[i];
		if (b[i] < b[tmp]) tmp = i;
	}
	ans += b[tmp];
	for (int i = 0; i < M; i++) {
		cin >> x >> y >> c;
		ans = min(ans, a[x - 1] + b[y - 1] - c);
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[int(input())-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(void){
  int n;
  cin >> n;
  int a, b;
  for(a = 1; a <= 9; a++){
      for(b = 1; b <= 9; b++){
          if(a * b == n){
              cout << "Yes" << endl;
              return 0;
          }
      }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long ll;
const int maxn = 2010;
const int mod = 1e9 + 7;
using namespace std;

inline ll mul(ll a,ll b) { return 1ll * a * b % mod; }

ll dp[maxn][maxn], fac[4000005], ifac[4000005];
int n, m, i, j, k, K;

inline ll qpow(ll a,int b,int p = mod) {
  ll res = 1;
  while(b) {
    if(b & 1) (res *= a) %= p;
    (a *= a) %= p;  b >>= 1;  
  }
  return res;
}

inline void pre_work(int N) {
  fac[0] = 1;
  for(int i = 1;i <= N;i++) fac[i] = (fac[i - 1] * i) % mod;
  ifac[N] = qpow(fac[N],mod - 2);
  //printf("%lld\n",ifac[N]);
  for(int i = N - 1;~i;i--) ifac[i] = (ifac[i + 1] * (i + 1)) % mod;
}

inline ll C(int n,int m) { return (((fac[m] * ifac[n]) % mod) * ifac[m - n]) % mod; }

int main()  {
  scanf("%d %d",&n,&K);  if(K == 1) return 0 & puts("1");
  dp[0][0] = 1;
  pre_work(4000000);
  for(int i = 1;i <= n;i++) {
      for(int j = 0;j <= i;j++) {
      dp[i][j] = dp[i - 1][j];  if(j == 0) continue;  int qwq;
      (dp[i][j] += dp[i][j - 1] * (n - j + 1) % mod * C(K - 2,n - i + (n - j + 1) * (K - 1) - 1) % mod) %= mod;
    }
  }
  printf("%lld\n",dp[n][n]);
  return 0;
}

Measured memory_bytes: 94208
D=int(input())
c = list(map(int,input().split()))
s=[[0 for e in range(26)] for f in range(D)]
for i in range(D):
 s[i]=list(map(int,input().split()))
last=[0]*26
ans=0
point=[0]*D
for i in range(D):
 saidai=-(10**10)
 kouho=0
 for j in range(26):
  if s[i][j]+c[j]*((i+1)-last[j])>=saidai:
   kouho=j+1
   saidai=s[i][j]+c[j]*((i+1)-last[j])
 print(kouho)


Measured memory_bytes: 9496
a = []
for i in range(5):
    a.append(int(input()))
    
b = []
c = []
for i in a:
    j = i % 10
    if j == 0:
        b.append(10)
    else:
        b.append(j)
    if (10-j) != 10:
        c.append(10 - j)
    else:
        c.append(0)
        
mini = b.index(min(b))

res = 0
for i, j in enumerate(a):
    if i != mini:
        res += j + c[i]
    else:
        res += j
        
print(res)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, M;
int S[2001], T[2001];
ll dp[2001] = {0}, dp2[2001] = {0};

int main() {
    fastio();
    cin >> N >> M;
    REP(i, N) cin >> S[i];
    REP(j, M) cin >> T[j];
    REP(i, N) {
        REP(j, M) {
            if(S[i] == T[j]) {
                dp[j] = 1;
                if(j > 0) dp[j] += dp2[j-1];
            } else dp[j] = 0;
        }
        ll s = 0;
        REP(j, M) {
            s += dp[j];
            if(s >= MOD) s-= MOD;
            dp2[j] += s;
            if(dp2[j] >= MOD) dp2[j] -= MOD;
        }
    }
    cout << (dp2[M-1] + 1) % MOD << endl;
	return 0;
}

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

int main(){
    int n, m, i;
    cin >> n >> m;
    int p[m] = {}, y[m] = {};
    vector<int> v[n+1];
    for(i=0; i<m; i++){
        cin >> p[i] >>  y[i];
        v[p[i]].push_back(y[i]);
    }
    for(i=0; i<=n; i++){
        sort(v[i].begin(), v[i].end());
    }
    for(i=0; i<m; i++){
        printf("%06d%06d\n", p[i], (int)(lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin()) + 1);
    }
    return 0;
}

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

using namespace std;

int main(void) {
     int n;
    cin >> n;
    set<string> free;
    //int ans = 0;

    for(int i = 0; i < n; i++){
        string tmp;
        cin >> tmp;
        free.insert(tmp);
    }
    //sort(free.begin(), free.end());
    // auto itr = unique(free.begin(), free.end());
    // free.erase(itr, free.end());

    cout << free.size() << endl;

    return 0;
}


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

int main(){
  int n,ans=0;
  cin>>n;
  vector<int> a(n,0),b(n,0),c(n,0);

  REP(i,n) cin>>a.at(i);
  REP(i,n) cin>>b.at(i);
  REP(i,n-1) cin>>c.at(i);
  
  REP(i,n){
    ans+=b.at(a.at(i)-1);
    if(i<n-1 && a.at(i)+1==a.at(i+1)) ans+=c.at(a.at(i)-1);
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long int ll;
typedef unsigned long long int ull;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >>a>>b>>s;
  s[b-1]=tolower(s[b-1]);
  cout <<s;
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <string.h>

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

const int MAX_N = 300010;
vi prime;
bool is_prime[MAX_N + 1];
void sieve(){
    memset(is_prime,false,sizeof(is_prime));
    for(int i = 1; i * 7 < MAX_N; i++) {
        int bef = i * 7 - 1;
        int aft = i * 7 + 1;
        is_prime[bef] = true;
        is_prime[aft] = true;
    }
    for(int i = 1; (i * 7) * (i * 7) <= MAX_N; i++) {
        int bef = i * 7 - 1;
        int aft = i * 7 + 1;
        if(is_prime[bef]) {
            for(int j = 2 * bef; j <= MAX_N; j += bef) is_prime[j] = false;
        }
        if(is_prime[aft]) {
            for(int j = 2 * aft; j <= MAX_N; j += aft) is_prime[j] = false;
        }
    }
    rep(i,MAX_N) if(is_prime[i]) prime.pb(i);
}

int main(){
    int n;
    sieve();
    while(cin >> n, n != 1) {
        cout << n << ":";
        rep(i,prime.size()){
            if(n % prime[i] == 0) cout << " " << prime[i];
        }
        cout << endl;
    }

    return 0;

}



Measured memory_bytes: 3388
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
cin>>a;
string ::iterator it=a.begin();
    sort(it,it+4);
    if(a[0]==a[1]&&a[2]==a[3]&&a[0]!=a[3])
    {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
n,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

rev=[None]*(n+1)
norm=[None]*(n+1)
revmax=[None]*(n+1)

rev[0]=(0,0)
revmax[0]=(0,0)
norm[0]=(0,0)
ans=0

# normal rotation
for i in range(1,n+1):
    x,v=l[i-1]
    norm[i]=(x,v+norm[i-1][1])

# reverse rotation
for i in range(1,n+1)[::-1]:
    x,v=l[i-1]
    if i==n:
        rev[i]=(c-x,v)
    else:
        rev[i]=(c-x,v+rev[i+1][1])

for i in range(1,n+1):
    revmax[-i]=(max(revmax[-i+1][0],rev[-i][1]-2*rev[-i][0]),max(revmax[-i+1][1],rev[-i][1]-rev[-i][0]))

for i in range(n+1):
    v1=norm[i][1]-norm[i][0]+revmax[i-n][0]
    v2=norm[i][1]-2*norm[i][0]+revmax[i-n][1]
    ans=max(ans,v1,v2)

print(ans)

Measured memory_bytes: 66168
nn, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(m)]
def check(n):
    ss = str(n)
    if len(ss) != nn: return False
    for s, c in sc:
        if ss[s-1] != str(c): return False
    return True

for i in range(1000):
    if check(i):
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,-1,0,1 };
const int LIT = -32768 * 100;

int n, m;
int arr[101];

void solve() {
	int d, t, s;
	cin >> d >> t >> s;
	if ((float)d / s <= (float)t) cout << "Yes";
	else cout << "No";
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	solve();
	return 0;
}


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

int main() {
  int count=0;
  int K,X;
  cin>>K>>X;
  if(500*K>=X){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}

Measured memory_bytes: 764
N,M,X,Y = map(int,input().split())
x = sorted(list(map(int,input().split())))
y = sorted(list(map(int,input().split())))

for z in range(X+1,Y+1):
    if x[-1]<z<=y[0]:
        print('No War')
        exit()
print('War')

Measured memory_bytes: 3060