akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=1010,O=1000000007;
inline int fpow(int x,lint n){
	int a=1;
	for(;n;n>>=1,x=(lint)x*x%O){
		if(n&1){
			a=(lint)a*x%O;
		}
	}
	return a;
}
struct Mat{
	const static int N=3;
	int a[N][N];
	inline friend Mat operator * (const Mat &a,const Mat &b){
		Mat c;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				lint tmp=0;
				for(int k=0;k<N;k++){
					tmp+=(lint)a.a[i][k]*b.a[k][j]%O;
				}
				c.a[i][j]=tmp%O;
			}
		}
		return c;
	}
}trans,res=(Mat){1,0,0,0,1,0,0,0,1};
inline void matfpow(lint n){
	if(n==0){
		res=(Mat){1,0,0,0,1,0,0,0,1};
		return;
	}
	matfpow(n>>1);
	res=res*res;
	if(n&1){
		res=res*trans;
	}
}
char mat[N][N];
inline int Main(){
	int n=ni,m=ni;
	lint tot=next_num<lint>();
	if(tot<=1)return 1;
	for(int i=1;i<=n;i++){
		scanf("%s",mat[i]+1);
	}
	int hor=0,ver=0;
	for(int i=1;i<=n;i++){
		hor+=mat[i][1]=='#'&&mat[i][m]=='#';
	}
	for(int j=1;j<=m;j++){
		ver+=mat[1][j]=='#'&&mat[n][j]=='#';
	}
	if(hor&&ver)return 1;
	if(!(hor||ver)){
		int cnt=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cnt+=mat[i][j]=='#';
			}
		}
		return fpow(cnt,tot-1);
	}
	if(ver){
		for(int i=1,ti=max(n,m);i<=ti;i++){
			for(int j=1;j<i;j++){
				swap(mat[i][j],mat[j][i]);
			}
		}
		swap(hor,ver),swap(n,m);
	}
	memset(&trans,0,sizeof(trans));
	for(int i=1;i<=n;i++){
		bool all=true;
		for(int j=1;j<=m;j++){
			if(mat[i][j]=='#'){
				trans.a[2][1]++;
				trans.a[2][2]++;
				if(mat[i][j-1]!='#'){
					trans.a[2][0]++;
					trans.a[2][1]++;
				}
			}else{
				all=false;
			}
		}
		if(all){
			trans.a[2][0]--;
			trans.a[0][0]++;
		}else if(mat[i][1]=='#'&&mat[i][m]=='#'){
			trans.a[2][0]-=2;
			trans.a[1][0]++;
		}
		if(mat[i][1]=='#'&&mat[i][m]=='#'){
			trans.a[2][1]-=2;
			trans.a[1][1]++;
		}
	}
	matfpow(tot-2);
	int vec[Mat::N]={0,0,0};
	for(int i=1;i<=n;i++){
		bool all=true;
		int cnt=0;
		for(int j=1;j<=m;j++){
			if(mat[i][j]=='#'){
				if(mat[i][j-1]!='#'){
					cnt++;
				}
			}else{
				all=false;
			}
		}
		if(all){
			vec[0]++;
		}else if(mat[i][1]=='#'&&mat[i][m]=='#'){
			vec[1]++;
			vec[2]+=cnt-2;
		}else{
			vec[2]+=cnt;
		}
	}
	lint ans=0;
	for(int i=0;i<Mat::N;i++){
		lint tmp=0;
		for(int j=0;j<Mat::N;j++){
			tmp+=(lint)res.a[i][j]*vec[j]%O;
		}
		ans+=tmp<<(i==1);
	}
	return ans%O;
}
int main(){
	printf("%d\n",Main());
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>

using namespace std;

string toJ(const string s)
{
    string tmp;

    tmp.push_back(s[s.size() - 1]);
    for (int i = 0; i < s.size() - 1; i++)
        tmp.push_back(s[i]);

    return tmp;
}

string toC(const string s)
{
    string tmp;

    for (int i = 1; i < s.size(); i++)
        tmp.push_back(s[i]);
    tmp.push_back(s[0]);

    return tmp;
}

string toE(const string s)
{
    string tmp;

    if (s.size() % 2) 
        tmp = s.substr(s.size() / 2 + 1, s.size() / 2) + s[s.size() / 2] +
            s.substr(0, s.size() / 2);
    else 
        tmp = s.substr(s.size() / 2, s.size() / 2) + s.substr(0, s.size() / 2);

    return tmp;
}

string toA(const string s)
{
    string tmp;

    for (int i = s.size() - 1; i >= 0; i--)
        tmp.push_back(s[i]);

    return tmp;
}

string toP(const string s)
{
    string tmp = s;

    for (int i = 0; i < tmp.size(); i++)
        if ('0' <= tmp[i]  && tmp[i] <= '9')
            tmp[i] = (((tmp[i] - '0') + 9) % 10) + '0';

    return tmp;
}

string toM(const string s)
{
    string tmp = s;

    for (int i = 0; i < tmp.size(); i++)
        if ('0' <= tmp[i]  && tmp[i] <= '9')
            tmp[i] = (((tmp[i] - '0') + 1) % 10) + '0';

    return tmp;
}

int main() 
{
    int n;

    cin >> n;
    while (n--) {
        string ord, mes;

        cin >> ord >> mes;

        for (int i = ord.size() - 1; i >= 0; i--) {
            if (ord[i] == 'J')
                mes = toJ(mes);
            else if (ord[i] == 'C')
                mes = toC(mes);
            else if (ord[i] == 'E')
                mes = toE(mes);
            else if (ord[i] == 'A')
                mes = toA(mes);
            else if (ord[i] == 'P')
                mes = toP(mes);
            else if (ord[i] == 'M')
                mes = toM(mes);
        }
        cout << mes << endl;
    }

    return 0;
}

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

int main() 
{
    int n; cin >> n;
    bitset<4004000>dp;
    dp[0]=1;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        int a; cin >> a;
        sum=sum+a;
        dp |= (dp<<a);
    }
    int ans=(sum+1)/2;
    while(!dp[ans])
    {
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int turnNum = sc.nextInt();
        int tPoint = 0;
        int hPoint = 0;

        for(int i = 0; i < turnNum; i++) {
        	String tStr = sc.next();
        	String hStr = sc.next();

        	int check = tStr.compareTo(hStr);
        	if(check < 0) {
        		hPoint += 3;
        	} else if(check == 0) {
        		tPoint += 1;
        		hPoint += 1;
        	} else if(check > 0) {
        		tPoint += 3;
        	}

        }

        System.out.println(tPoint + " " + hPoint);

    }
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//桁数
ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//約数全列挙
vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//累乗(xのn乗%mod)
ll modpow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//階乗
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}

ll modinv(ll a, ll mod)
{
  ll b = mod, u = 1, v = 0;
  while (b)
  {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

void Main()
{
  ll n, m; cin >> n >> m;
  if(abs(n - m) > 1) fin(0);
  ll ans = 1;
  for(ll i = 2;i <= n;i++)
  {
    ans *= i;
    ans %= MOD;
  }
  for(ll i = 1;i <= m;i++)
  {
    ans *= i;
    ans %= MOD;
  }
  if(abs(m - n) == 0) ans *= 2;
  ans %= MOD;
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	bool ret = true;
	char S[200]; scanf("%s", S);
	int cur = 0;
	while ('\0' != S[cur]){
		if (0 == (cur % 2)){
			if ('L' == S[cur]){
				ret = false;
			}
		}
		else{
			if ('R' == S[cur]){
				ret = false;
			}
		}
		cur++;
	}

	if (ret){
		printf("Yes");
	}
	else{
		printf("No");
	}

	return 0;
}

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

class BIT{
    ll bit[100010] = {};
public:
    BIT(){;}
    void insert(ll k) {
        ll tmp = k;
        while (tmp < 100010) {
            bit[tmp]++;
            tmp += -tmp & tmp;
        }
    }
    ll find(ll k) {
        ll tmp = k;
        ll ret = 0;
        while (tmp > 0) {
            ret += bit[tmp];
            tmp -= -tmp & tmp;
        }
        return ret;
    }
};

ll n;
ll a[100010];
ll l[100010];
ll r[100010];

int main() {
    BIT b1, b2;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    for (int i = 0; i < n; i++) {
        l[i] = i - b1.find(a[i]);
        b1.insert(a[i]);
    }

    reverse(a,a+n);
    for (int i = 0; i < n; i++) {
        r[i] = i - b2.find(a[i]);
        b2.insert(a[i]);
    }
    reverse(r,r+n);

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += min(l[i], r[i]);
    }

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



Measured memory_bytes: 6992
#include <stdio.h>
#include <string.h>

int main(){
int n,a,b,ab,o;
char blood[3];
a = b = ab = o = 0;
while(scanf("%d,%s",&n,blood) != EOF){
if(!strcmp(blood,"A")) a++;
if(!strcmp(blood,"B")) b++;
if(!strcmp(blood,"AB")) ab++;
if(!strcmp(blood,"O")) o++;
}

printf("%d\n%d\n%d\n%d\n",a,b,ab,o);

return 0;
} 

Measured memory_bytes: 0
#include <iostream>
#include <vector>
using namespace std;
typedef long long i64;
typedef char str255[256];

#define BIG_PRIME 1000000007
#define remainder(x) ((x) % BIG_PRIME)
#define long long long

int A, B;

void Solve()
{
  cout << 6 - (A + B) << endl;
}

void Init()
{
  cin >> A >> B;
}

void Clean()
{
}

int main(){ Init(); Solve(); Clean(); return 0; }


Measured memory_bytes: 256
N = int(input())
S = list(map(str, input()))
flg = 1
if N % 2 != 0:
	print("No")
else:
	for i in range(N // 2):
		if S[i] != S[N // 2 + i]:
			flg = 0
			break
	if flg:
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 38616
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) cout << #var << ": " << var << endl
using namespace std;
using Int = int64_t;
using Uint = uint64_t;
constexpr Uint mod = 1e9 + 7;
constexpr Int INF = INT_MAX;
template<typename T>
using Grid = vector<vector<T>>; // 二次元配列。[y][x]
template<typename T, typename U>
using Umap = unordered_map<T, U>;
template<typename T>
using Uset = unordered_set<T>;
template<typename T>
using P = pair<T, T>;

//numの各桁を返す。 例: digit(702) == {7, 0, 2} 計算量O(log10(n))
auto digit(Int num) {
	vector<Int> res = { num % 10 };
	Int tmp = num / 10;
	while (tmp) {
		res.push_back(tmp % 10);
		tmp /= 10;
	}

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

	return res;
}


void calc() {

	Int N, M; cin >> N >> M;
	vector<Int> s(M), c(M);
	rep(i, M)cin >> s[i] >> c[i];

	Int begin = pow(10, N - 1), end = pow(10, N);
	if (N == 1)begin = 0;
	Int ans = -1;

	//N == 4の場合、1000から9999を全探索
	for (Int num = begin; num < end; ++num) {
		auto digits = digit(num);
		bool flag = true;
		rep(i, M) {
			if (digits[s[i] - 1] != c[i])flag = false;
		}
		if (flag) {
			ans = num;
			break;
		}
	}

	cout << ans << endl;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 512
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
cnt = 0
0.step(a) do |a|
  0.step(b) do |b|
    0.step(c) do |c|
     cnt += 1 if 500*a + 100*b + 50*c == x 
    end
  end
end
puts cnt

Measured memory_bytes: 1916
# coding=utf-8
# Date: 2020-01-08
# Author: lee215

get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]


N, K = gets()
H = sorted(gets())
print sum(H[:max(0, N - K)])


Measured memory_bytes: 20060
<?php

$input = explode(' ', trim(fgets(STDIN)));
$n = (int)$input[0];
$q = (int)$input[1];

$s = trim(fgets(STDIN));

$t = [];
$d = [];
for ($j=1; $j <= $q; $j++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$t[] = $input[0];
	$d[] = $input[1];
}

$left = 0;
$right = $n;
$l_idx = -1;
while ($left < $right) {
	$mid = (int)floor(($left+$right)/2);
	if (toLeft($mid)) {
		$left = $mid + 1;
		$l_idx = max($l_idx, $mid);
	}else{
		$right = $mid;
	}
}
$left = 0;
$right = $n;
$r_idx = $n;
while ($left < $right) {
	$mid = (int)floor(($left+$right)/2);
	if (toRight($mid)) {
		$right = $mid;
		$r_idx = min($r_idx, $mid);
	}else{
		$left = $mid + 1;
	}
}
// echo 'l: ' . $l_idx . PHP_EOL;
// echo 'r: ' . $r_idx . PHP_EOL;
if ($l_idx > $r_idx) {
	echo 0;
}else{
	echo $n - ($l_idx+1 + ($n - $r_idx));
}




function toLeft($p){
	global $q;
	global $s;
	global $n;
	global $t;
	global $d;
	$res = false;
	for ($i=0; $i < $q; $i++) { 
		$tmp_s = $s[$p];
		if ($t[$i] === $tmp_s) {
			if ($d[$i] === 'L') {
				--$p;
			}else{
				++$p;
			}
		}
		if ($p < 0) {
			$res = true;
			break;
		}
		if ($p > $n-1) {
			break;
		}
	}
	return $res;
}
function toRight($p){
	global $q;
	global $s;
	global $n;
	global $t;
	global $d;
	$res = false;
	for ($i=0; $i < $q; $i++) { 
		$tmp_s = $s[$p];
		if ($t[$i] === $tmp_s) {
			if ($d[$i] === 'L') {
				--$p;
			}else{
				++$p;
			}
		}
		if ($p > $n-1) {
			$res = true;
			break;
		}
		if ($p < 0) {
			break;
		}
	}
	return $res;
}

Measured memory_bytes: 33260
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
using namespace std;
int main(){
  int n,i;
  cin >> n >> i;
  cout << n - i + 1 << '\n';
  return 0;
}

Measured memory_bytes: 256
#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 = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 998244353;
//////////////https://drken1215.hatenablog.com/entry/2018/06/08/210000
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
///////////////////////////////////////////////////////////////////////
int main()
{
    COMinit();
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    ll ans = 0;
    rep(i, n + 1)
    {
        ll x = a * (ll)i;
        if ((x > k) || (((k - x) % b) != 0))
        {
            continue;
        }
        ll j = (k - x) / b;
        if (j > n)
        {
            continue;
        }
        ans += (COM(n, i) * COM(n, j)) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define M 1000005
#define ii pair<ll, ll>
#define fi first
#define se second

ll n, a[1000], b[1000], c[1000];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], c[i] = i;
    bool check = false;
    bool tmp = true;
    for (int i = 1; i <= n; i++) 
        if (c[i] != a[i]) tmp = false;
    if (tmp) check = true;
    for (int i = 1; i < n; i++){
        for (int j = i + 1; j <= n; j++){
            for (int k = 1; k <= n; k++) b[k] = a[k];
            swap(b[i], b[j]);
            bool ch = true;
            for (int k = 1; k <= n; k++){
                if (c[k] != b[k]) ch = false;
            }
            if (ch) check = true;
        }
    }
    if (check) cout << "YES";
    else cout << "NO";
    return 0;
}

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

ll dp[101][101][301];

int main()
{
	ll n,W;
	cin >> n >> W;
	vector<ll>w(n),v(n);

	for(int i =0 ;i<n;i++)
	{
		cin >> w[i] >> v[i];
	}
	ll base = w[0];

	for(int i = 0;i<n;i++)w[i]-=base;

	for(int i = 0;i<n;i++)
	{
		for(int j = 1;j<=n;j++)//個数
		{
			for(int k = 0;k<=300;k++)//重さ
			{
				//cout << i << ';' << j << ';' << k << endl;
				if(k-w[i]>=0)dp[i+1][j][k] = max(dp[i][j][k],dp[i][j-1][k-w[i]]+v[i]);
				else dp[i+1][j][k] = dp[i][j][k];
				
			}
		}
	}
	ll ans = 0;

	for(int i = 0;i<=n;i++)
	{
		for(int j=0;j<=300;j++)
		{
			ll tmp = base*i + j;
			if(tmp<=W)ans = max(ans,dp[n][i][j]);
			
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 27364
import java.util.Scanner;

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


				int j = sc.nextInt();
				int a;
				int flag = 0;

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

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				}
				System.out.println();
	}
}

Measured memory_bytes: 28708
def euler_phi(n):
    res = n
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            while n % i == 0:
                n //= i
            res -= res // i
    if n > 1:
        res -= res // n
    return res

n = int(input())
print(euler_phi(n))


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

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

    int n, m, r;
    cin >> n >> m >> r;

    int D[n][n];
    REP(i, n){
        REP(j, n){
            if(i == j) D[i][j] = 0;
            else D[i][j] = 1e9;
        }
    }

    vector<int> R(r);
    REP(i, r){
        cin >> R[i];
        R[i]--;
    }
    sort(R.begin(), R.end());

    REP(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        D[a][b] = c;
        D[b][a] = c;
    }

    REP(i, n){
        REP(j, n){
            REP(k, n){
                D[j][k] = min(D[j][k], D[j][i] + D[i][k]);
            }
        }
    }

    int mini = 1e9;
    do{
        int s, cost = 0;
        REP(i, r){
            if(i){
                cost += D[s][R[i]];
                s = R[i];
            }else s = R[i];
        }
        mini = min(mini, cost);
    }while(next_permutation(R.begin(), R.end()));

    cout << mini << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
ll n,ans=0,wh;
int main()
{
	bool pri[1000055]={0};
	cin>>n;
	if(n==1) re(0)
	wh=sqrt(n)+5;
	rep2(i,2,wh)
	{
		if(pri[i]==0)
		{
			int k=0,minus=1;
			while(n%i==0)
			{
				n/=i;
				k++;
			}
			while(k-minus>=0) k-=minus,minus++,ans++;
			for(int j=2*i;j<=wh;j+=i)
			pri[j]=1;
		}
	}
	if(n!=1) ans++;
	if(ans==0) re(1)
	re(ans) 
	return 0;}

Measured memory_bytes: 4592
#include <iostream>
std::string s;
int main(){
    std::ios::sync_with_stdio(false);
    std::cin>>s;
    for(int i=0,j=s.size();i<j;++i)
        if(s[i]=='A')
            for(int k=j-1;k>=0;--k)
                    if(s[k]=='Z'){
                        std::cout<<k-i+1<<'\n';
                        return 0;
                    }
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b, c;
  cin >> a >> b >> c;

  if (a == b) cout << c << endl;
  if (b == c) cout << a << endl;
  if (c == a) cout << b << endl;
}


Measured memory_bytes: 3592
package main

import "fmt"

func main() {
	var a string
	fmt.Scanf("%s", &a)

	if a == "a" {
		fmt.Printf("%s\n", "b")
	} else if a == "b" {
		fmt.Printf("%s\n", "c")
	} else if a == "c" {
		fmt.Printf("%s\n", "d")
	} else if a == "d" {
		fmt.Printf("%s\n", "e")
	} else if a == "e" {
		fmt.Printf("%s\n", "f")
	} else if a == "f" {
		fmt.Printf("%s\n", "g")
	} else if a == "g" {
		fmt.Printf("%s\n", "h")
	} else if a == "h" {
		fmt.Printf("%s\n", "i")
	} else if a == "i" {
		fmt.Printf("%s\n", "j")
	} else if a == "j" {
		fmt.Printf("%s\n", "k")
	} else if a == "k" {
		fmt.Printf("%s\n", "l")
	} else if a == "l" {
		fmt.Printf("%s\n", "m")
	} else if a == "m" {
		fmt.Printf("%s\n", "n")
	} else if a == "n" {
		fmt.Printf("%s\n", "o")
	} else if a == "o" {
		fmt.Printf("%s\n", "p")
	} else if a == "p" {
		fmt.Printf("%s\n", "q")
	} else if a == "q" {
		fmt.Printf("%s\n", "r")
	} else if a == "r" {
		fmt.Printf("%s\n", "s")
	} else if a == "s" {
		fmt.Printf("%s\n", "t")
	} else if a == "t" {
		fmt.Printf("%s\n", "u")
	} else if a == "u" {
		fmt.Printf("%s\n", "v")
	} else if a == "v" {
		fmt.Printf("%s\n", "w")
	} else if a == "w" {
		fmt.Printf("%s\n", "x")
	} else if a == "x" {
		fmt.Printf("%s\n", "y")
	} else if a == "y" {
		fmt.Printf("%s\n", "z")
	}
}

Measured memory_bytes: 512
N, M = gets.split.map(&:to_i)
LRD = M.times.map { gets.split.map(&:to_i) }
e = Array.new(N+1) { Array.new }

LRD.each do |l, r, d|
  e[l] << [r,d]
  e[r] << [l,-d]
end

c = Array.new(N+1, nil)
(1..N).each do |n|
  next unless c[n].nil?
  q = [[n, 0]]
  q.each do |v, d|
    if !c[v].nil?
      if c[v] != d
        puts 'No'
        exit
      end
      next
    end
    c[v] = d
    e[v].each do |ne, nd|
      q << [ne, d+nd]
    end
  end
end

puts 'Yes'


Measured memory_bytes: 64788
from collections import defaultdict
N, K = [int(x) for x in input().split()]
P = [0] + [int(x) for x in input().split()]
C = [0] + [int(x) for x in input().split()]

max_score = max(C[1:])

for init in range(1, N + 1):   # 初めの場所をiとする
    score = defaultdict(int)  # int/bool/list....
    visited = [-1] * (N + 1)
    visited[init] = 0  # 何回移動後に着いたか？
    i = init
    for k in range(1, K + 1):
        prev = i
        i = P[i]    # k回移動後に着くところ

        if visited[i] < 0:  # まだ訪れてなかった
            visited[i] = k
            score[i] = score[prev] + C[i]
            max_score = max(max_score, score[i])
            continue

        loop_score = (score[prev] + C[i]) - score[i]
        loop_len = k - visited[i]

        score[i] = score[prev] + C[i]

        loop_num = (K - k) // loop_len # ループをあと何回回れるか
        loop_rem = (K - k) % loop_len

        if loop_num > 0 and loop_rem == 0:
            loop_num -= 1
            loop_rem = loop_len

        j = i   # ループを開始するノードから
        temp = 0
        rem_max = 0
        for _ in range(loop_rem):
            j = P[j]
            temp += C[j]
            rem_max = max(rem_max, temp)

        max_score = max(max_score, score[i] + loop_num * loop_score + rem_max)
        break

print(max_score)

Measured memory_bytes: 144504
#include<iostream>
using namespace std;
int main(void) {
    int a, b, c, n = 0;
    cin >> a >> b >> c;
    for(int i = a; i <= b; i++){
        if(c % i == 0){
            n++;
        }
    }
    cout << n << endl;
    return 0;
}

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

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

int main(){
    int n,m;
    cin>>n>>m;
    int sum=0;
    for(int i=0;i<m;i++){
        int tmp;
        cin>>tmp;
        sum+=tmp;
    }
    if(n<sum){
        cout<<-1<<endl;return 0;
    }
    cout<<n-sum<<endl;
    return 0;
}

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

int main(void)
{
    string weather;
    cin >> weather;
    if (weather == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (weather == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string t,p;
    cin>>t>>p;
    int st=t.size(),sp=p.size();
    rep(i,st){
        bool flag=true;
        rep(j,sp)if(t[i+j]!=p[j]) flag=false;
        if(flag) cout<<i<<endl;
    }
    return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string s;
ll rec(ll inv,ll out,ll val)
{
	if(inv==s.size())
	return (out*(val==0));
	return (rec(inv+1,out,10*val+s[inv]-'0')+rec(inv+1,out+10*val+s[inv]-'0',0));
}
int main()
{
	cin >>s;
	cout <<rec(0,0,0)<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        bool R = false;
        bool S = false;
        string Q = Console.ReadLine();
        for (int i = 0; i < Q.Length; i++)
        {
            if (Q[i] == 'C') R = true;
            if (R && (Q[i] == 'F')) S = true;
        }
        if (S) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 2648
n = int(input())
a = list(map(int,input().split()))
if a == [1]*n:
    print("pairwise coprime")
    quit()
m = max(a)
l = [-1]*(m+3)
for i in range(2,m+1):
    if l[i] != -1:
        continue
    l[i] = i
    j = 2
    while i*j <= m:
        if l[i*j] == -1:
            l[i*j] = i
        j += 1
def fastfact(i,lst):
    if l[i] == -1:
        return lst
    while i > 1:
        lst.append(l[i])
        i //= l[i]
    return lst
check = [0]*(m+1)
for i in range(n):
    if a[i] == 1:
        continue
    s = set(fastfact(a[i],[]))
    for j in s:
        check[j] += 1
M = max(check)
if M == 1:
    print("pairwise coprime")
elif M == n:
    print("not coprime")
else:
    print("setwise coprime")

Measured memory_bytes: 196732
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

bool prime(int number) {
  for(int i = 2; i <= (int)sqrt(number); ++i) {
    if(number % i == 0) return false;
  }
  return true;
}

int main() {
  int N; cin >> N;
  vector<int> vec;
  for(int i = 11; i <= 55555; i += 10) {
    if(prime(i)) vec.push_back(i);
  }
  for(int i = 0; i < N; ++i) {
    if(i != N-1) cout << vec[i] << " ";
    else cout << vec[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

int n;
int D[500001];
int P[500001];
bool ans[500001];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> P[0];
    for (int i = 1; i <= n; ++i) {
        cin >> D[i];
    }
    for (int i = 1; i <= n; ++i) {
        P[i] = min(P[i - 1], abs(P[i - 1] - D[i]));
    }
    llong mx = 0;
    for (int i = n; i > 0; i--) {
        if (P[i - 1] <= mx) ans[i] = 1;
        if (D[i] / 2 <= mx) {
            mx += D[i];
        }
    }
    int q;
    cin >> q;
    while (q--) {
        int x;
        cin >> x;
        printf(ans[x] ? "NO\n" : "YES\n");
    }
    return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 1e5+10;
int n, a[MAXN];

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a, a+n); // must have at least one positive number
  reverse(a, a+n);// first number is the biggest so take positive of it
  int tot = a[0]-a[n-1];
  vector<int> pos, neg;
  pos.push_back(a[0]);
  neg.push_back(a[n-1]);
  for(int i=1;i<n-1;i++) {
    if (a[i]<0) {
      tot+=-a[i];
      neg.push_back(a[i]);
    }
    else {
      tot +=a[i];
      pos.push_back(a[i]);
    }
  }
  cout << tot <<endl;
  // at least one in pos and at least one in neg
  int left = a[0];
  int right = a[n-1];
  for(int i=1;i<n-1;i++) {
    if (a[i]<0) {
      cout << left << " " << a[i] <<endl;
      left-=a[i];
    }
    else {
      cout << right << " " << a[i] <<endl;
      right-=a[i];
    }
  }
  cout << left << " " << right <<endl;
}


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

int main(int argc, char *argv[])
{
	string n;
	cin >> n;
	char ld = *(n.end() - 1);
	if (ld == '3') {
		cout << "bon";
	} else if (ld == '0' || ld == '1' || ld == '6' || ld == '8') {
		cout << "pon";
	} else {
		cout << "hon";
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<ll> H(N);
  rep(i, N) cin >> H[i];

  if (N == 1) {
    puts("Yes");
    return 0;
  }

  int b = 0, e = 1;
  for (int i = 0; i < N - 1; i++) {
    if (H[i] > H[i + 1]) {
      for (int j = b; j < e; j++) {
        H[j] -= 1;
      }
    } else {
      if (H[i] == H[i + 1])
        e++;
      else {
        b = i + 1;
        e = b + 1;
      }
    }
  }

  bool flag = true;
  for (int i = 0; i < N - 1; i++) {
    if (H[i] > H[i + 1]) {
      flag = false;
      break;
    }
  }

  if (flag)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 1024
#include<stdio.h>

static const unsigned long den=1000000007;

unsigned long Power(int n, unsigned long m) {
    unsigned long res = 1;
    if (n>0) {
        res = Power(n/2, m);
        if (n%2==0) res = (res*res)%den;
        else res = (((res*res)%den)*m)%den;
    }
    return res;
}

int main() {
    int n;
    unsigned long m;

    scanf("%lu %d", &m, &n);

    m = Power(n, m);

    printf("%lu\n", m);

    return 0;
}


Measured memory_bytes: 2760
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<sstream>
#include<map>
#include<queue>
using namespace std;
#define int long long
map<string, int> mp;
vector < vector<int> >g;
vector < vector<int> >c;
vector<vector<int> > list;
signed main() {
	int N, T;
	cin >> N >> T;
	string A, B;
	cin >> A >> B;
	mp[A] = 0;
	mp[B] = 1;
	int M = 2;
	list.resize(M);
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		vector<string> S(a);
		vector<int>t(a - 1);
		int X = g.size();
		for (int j = 0; j < a; j++) {
			cin >> S[j];
			if (mp.count(S[j]) == 0) {
				mp[S[j]] = M;
				M++;
				list.push_back(vector<int>(0));
			}
			list[mp[S[j]]].push_back(X + j);
			g.push_back(vector<int>(0));
			c.push_back(vector<int>(0));
		}
		for (int j = 0; j < a - 1; j++) {
			cin >> t[j];

			g[X + j].push_back(X + j + 1);
			c[X + j].push_back(t[j]);
			g[X + j + 1].push_back(X + j);
			c[X + j + 1].push_back(t[j]);
		}
	}
	int X = g.size();
	for (int i = 0; i < M; i++) {
		g.push_back(vector<int>(0));
		c.push_back(vector<int>(0));
	}
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < list[i].size(); j++) {
			g[list[i][j]].push_back(X + i);
			c[list[i][j]].push_back(0);
			g[X + i].push_back(list[i][j]);
			c[X + i].push_back(T);
		}
	}
	int INF = (int)1 << 60;
	vector<pair<int, int> > dp(g.size(), make_pair(INF, INF));
	dp[X] = make_pair(0, 0);
	priority_queue<pair<pair<int, int>, int> > pq;
	pq.push(make_pair(make_pair(0, 0), X));
	pair<pair<int, int>, int> t;
	int cur = 0;
	pair<int, int>ne;
	while (!pq.empty()) {
		t = pq.top(); pq.pop();
		cur = t.second;
		for (int i = 0; i < g[cur].size(); i++) {
			ne = dp[cur];
			ne.first += c[cur][i];
			if (cur >= X)ne.second++;
			if (dp[g[cur][i]] > ne) {
				dp[g[cur][i]] = ne;
				ne.first = -ne.first;
				ne.second = -ne.second;
				pq.push(make_pair(ne, g[cur][i]));
			}
		}
	}

	//for (auto m : mp) {
	//	cerr << m.first << " " << m.second << endl;
	//}
	//cerr << "X=" << X << endl;
	//for (int i = 0; i < g.size(); i++) {
	//	for (int j = 0; j < g[i].size(); j++) {
	//		cerr << i << " " << g[i][j] << " " << c[i][j] << endl;
	//	}
	//}

	if (dp[X + 1].first < INF) {
		cout << dp[X + 1].first - T << " " << dp[X + 1].second - 1 << endl;
	}
	else {
		cout << -1 << endl;
	}
}


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

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var L = input[0];
        var R = input[1];
        var d = input[2];

        Console.WriteLine(R / d - (L - 1) / d);
    }
}

Measured memory_bytes: 28124
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    int ans = 0;
    int v[n], c[n];
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }

    for (int i = 0; i < n; i++) {
        ans += max(0, v[i] - c[i]);
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int a, b, c;
   cin >> a >> b >> c;

   if(a + b >= c){
      cout << "Yes" << endl;
   }
   else{
      cout << "No" << endl;
   }

   return 0;
}

Measured memory_bytes: 256
package main
 
import (
  "fmt"
)
 
 
func main() {
  var a, b, c int
  fmt.Scan(&a, &b, &c)
  
  var fullCount = b / a
  
  if c < fullCount {   
    fmt.Print(c)
  } else {
    fmt.Print(fullCount)
  }
}

Measured memory_bytes: 512
from operator import itemgetter

n, m= map(int, (input().split()))
pyi = [list(map(int, (input().split()))) + [i] for i in range(m)]
pyi.sort(key=itemgetter(1))
pyi.sort(key=itemgetter(0))
cityflag = 0
ans = []
for rep in range(m):
    if pyi[rep][0] != pyi[rep - 1][0]:
        cityflag = 0

    cityflag += 1
    ans += [[pyi[rep][0] , cityflag, pyi[rep][2]]]

for i in sorted(ans, key=itemgetter(2)):
    print(str(i[0]).zfill(6) + str(i[1]).zfill(6))

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

int main()
{
    int r,g,b;
    int sum;
    cin >> r >> g >> b;

    sum = 100*r + 10*g + b;

    if(sum % 4 == 0)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S, T; cin >> S >> T;
  bool Yes=true;
  int Slength=S.size();
  
  for (int i=0; i<Slength; i++){
    if (S.at(i)!=T.at(i)){
      Yes=false;
      cout << "No" << endl;
      break;
      }
    }
  if(Yes){cout << "Yes" << endl;}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const unsigned int BIT_FLAG_0 = (1 << 0);  // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1);  // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2);  // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3);  // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4);  // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5);  // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6);  // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7);  // 0000 0000 1000 0000

const double PI = 3.14159265358979323846;

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

#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    rep(i, S.size()) {
        cout << char((S[i] - 'A' + N) % 26 + 'A');
    }
    cout << endl;
}


Measured memory_bytes: 3580
val max = 200000

val factorial = LongArray(max + 1)
val inverse = LongArray(max + 1)
val factorialInverse = LongArray(max + 1)

fun main(args: Array<String>) {
    val mod = 1000000007
    val (H, W, A, B) = readInputLine().split(" ").map { it.toInt() }
    
    factorial[0] = 1L
    factorial[1] = 1L
    inverse[0] = 1L
    inverse[1] = 1L
    factorialInverse[0] = 1L
    factorialInverse[1] = 1L
    for (i in 2..max) {
        factorial[i] = (factorial[i - 1] * i.toLong() % mod)
        inverse[i] = (mod - inverse[mod.toInt() % i] * (mod / i.toLong()) % mod)
        factorialInverse[i] = (factorialInverse[i - 1] * inverse[i] % mod)
    }

    var ans = factorial[H + W - 2] * (factorialInverse[H - 1] * factorialInverse[W - 1] % mod) % mod
    
    for (i in 0 until B) {
        ans -= factorial[H - A - 1 + i] * (factorialInverse[H - A - 1] * factorialInverse[i] % mod) % mod * factorial[A + W - i - 2] % mod * (factorialInverse[A - 1] * factorialInverse[W - i - 1] % mod) % mod
        if (ans < 0) {
            ans += mod
        }
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 45024
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
//--
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<complex>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef complex<double> pt;

double dot(pt a,pt b){return (conj(a)*b).real();}
double cros(pt a,pt b){return (conj(a)*b).imag();}
pt proj(pt a,pt to){
  return dot(a,to)/norm(to)*to;
}

pt refle(pt a,pt mirror){
  return pt(2)*proj(a,mirror)-a;
}

int pt3(pt a,pt b,pt c){
  pt p=b-a,q=c-a;
  double tmp;
  tmp=cros(p,q);
  if(tmp>0){
    return 0;
  }else if(tmp<0){
    return 1;
  }else if(norm(p+q)<max(norm(p),norm(q))){
    return 2;
  }else if(norm(q)>norm(p)){
    return 3;
  }else if(norm(q)<norm(p)){
    return 4;
  }
  return 5;
}
int main(){
  int i,j,k,n;
  pt o,p,q;
 // cout<<cros(pt(1,0),pt(0,-1))<<endl;
  cin>>o.real()>>o.imag()>>p.real()>>p.imag();
  cin>>n;
  char str[][100]={"COUNTER_CLOCKWISE","CLOCKWISE","ONLINE_BACK"
    ,"ONLINE_FRONT","ON_SEGMENT","ON_SEGMENT"};
  double a,b;
  rep(i,n){
    cin>>a>>b;
    q=pt(a,b);
    printf("%s\n",str[pt3(o,p,q)],a,b);
  }
  return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int compare_int(const void *a, const void *b)
{
    return *(long long*)a - *(long long*)b;
}

int min_comp(int min, int a)
{

}
int max_comp(int max, int a)
{
  if(max>a)    return max;
  else    return a;
}


int main()
{
  int A, B, C, X, Y;
  int m[101]={};
  int min;
//  long long N[101]={};
  int i,j;
  int cnt=0;
  int temp=0;
//    int k=0;

  scanf("%d %d %d %d %d", &A ,&B, &C, &X, &Y);
  //printf("%d\n", A);
  
  if((A+B)>=(2*C)){
    if(X<Y) {
      cnt = X * 2 * C;
//  printf("0 %d\n", cnt);
      if(B<(2*C)) cnt = cnt + ((Y-X) * B);
      else cnt = cnt + ((Y-X) * 2 * C);
//  printf("0 %d\n", cnt);
    } else {
      cnt = Y * 2 * C;
      if(A<(2*C)) cnt = cnt + ((X-Y) * A);
      else cnt = cnt + ((X-Y) * 2 * C);
//  printf("1 %d\n", cnt);
    }
  } else {
      cnt = (A * X) + (B * Y);
//  printf("2 %d\n", cnt);
  }

/*  
  for(i=0;i<N;i++){
    if(min>m[i]) min =m[i];
    X = X - m[i];
    cont++;
  }
  cont = cont + (X/min);
*/  
  printf("%d\n", cnt);
 
  //  else printf("No\n"); 
return 0;
}


Measured memory_bytes: 128
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort()
mod = 10 ** 9 + 7

def make_tables(n, mod = 10 ** 9 + 7):
    fac = [1, 1] # 階乗テーブル
    finv = [1, 1] #逆元の階乗テーブル
    inv = [0, 1] #逆元テーブル

    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % mod)
        inv.append((mod -inv[mod % i] * (mod // i)) % mod)
        finv.append((finv[-1] * inv[-1]) % mod)
    return fac, finv

def nCk(n, k, mod = 10 ** 9 + 7):
    k = min(k, n-k)
    return fac[n] * finv[k] * finv[n-k] % mod

fac, finv = make_tables(N)

MAX = 0
MIN = 0

for i in range(N - K + 1):
    MIN -= nCk(N - i - 1, K - 1) * A[i]
    MIN %= mod

A = sorted(A, reverse=True)

for j in range(N - K + 1):
    MAX += nCk(N - j - 1, K - 1) * A[j]
    MAX %= mod

print((MAX + MIN) % mod)

Measured memory_bytes: 76712
s=input()
n=len(s)-1
l=[]
for i in range(n):
    l.append("+")
sum = 0

if len(s) < 2:
    sum = s

else:
    for i in range(2 ** n):
        plus = []
        tmp = ""
        ans = 0
        for j in range(n):
            if ((i>>j) & 1):
                plus.append(l[j])
            else:
                plus.append("")
        for i in range(n):
            tmp += s[i]+plus[i]
            if i == n-1:
                tmp+=s[i+1]
        tmp2 = tmp.split("+")
        for i in range(len(tmp2)):
            ans += int(tmp2[i])
        sum+=ans

print(sum)



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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000003;
#define MAX_X 1000010

struct mint {
    ll x;
    mint(ll x = 0) : x(x % MOD) {}
    mint& operator += (const mint a) {
        if ( (x += a.x) >= MOD) { x -= MOD; }
        return *this;
    }
    mint& operator -= (const mint a) {
        if ( (x += MOD - a.x) >= MOD) { x -= MOD; }
        return *this;
    }
    mint& operator *= (const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator + (const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator - (const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator * (const mint a) const {
        mint res(*this);
        return res *= a;
    }
};

// x の y 乗を求める O(log MOD)
ll modpow(ll x, ll y) {
    if (y == 0) return 1;
    ll res = modpow(x, y / 2);
    return res * res % MOD * (y & 1 ? x : 1) % MOD;
}
// x の逆元を求める O(logMOD)
ll modinv(ll x) { return modpow(x, MOD - 2); }
mint modinv(mint x) { return modpow(x.x, MOD - 2); }

// n の m 上昇階乗べきを求める O(log MOD)
// fact には [0, mod] の階乗を事前計算したものを渡す
// 例) 4 の 3 上昇階乗べき -> 4 * (4+1) * (4+2)
ll raising_fact(const vector<mint>& fact, ll n, ll m) {
    // 剰余の関係上 MOD! 以上の階乗は 0 になる
    if(n + m - 1 >= MOD) { return 0; }

    mint ret = fact[ n + m - 1 ];
    ret *= modinv(fact[ n - 1 ]);
    return ret.x;
}

// 等差数列の積を求める O(log MOD)
// 初項 x, 公差 d, 第 n 項までを求める
// MOD は 10^6 程度までが限界
// fact には [0, mod] の階乗を事前計算したものを渡す
// 例) x = 3, d = 1, n = 4 -> 3 * 4 * 5 * 6 = 360
ll AriProMul(const vector<mint>& fact, ll x, ll d, ll n) {
    mint x_d = mint(x) * mint(modinv(d));
    // d が 0 のときは例外 -> x^n になる
    if(d == 0) { return modpow(x, n); }
    return (modpow(d, n) * raising_fact(fact, x_d.x, n)) % MOD;
}

ll Q;
vector<mint> fact;    // 階乗 i!

signed main()
{
    cin >> Q;

    // fact の作成
    fact.resize(MAX_X);
    fact[0] = 1;
    for(int i = 1; i < MAX_X; ++i) { fact[i] = fact[i-1] * i; }

    REP(i, Q) {
        ll x, d, n;
        cin >> x >> d >> n;
        ll ans = AriProMul(fact, x, d, n);
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 8704
from itertools import permutations


def main():
    N = int(input())
    cities = [i for i in range(N)]
    xys = []
    for _ in range(N):
        xys.append(list(map(int, input().split())))

    combs = list(permutations(cities))
    sum_dist = 0
    for comb in combs:
        for i in range(len(comb)-1):
            idx1 = comb[i]
            idx2 = comb[i+1]
            sum_dist += (
                (xys[idx1][0] - xys[idx2][0]) ** 2 +
                (xys[idx1][1] - xys[idx2][1]) ** 2) ** 0.5
    print(sum_dist / len(combs))


if __name__ == '__main__':
    main()


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

int n,m,vis[500*500],bcnt;
vector<int> edge[500*500];
char s[500][500];

int getnode(int x,int y)
{
	return (x-1)*m+y;
}

int dfs(int u)
{
	int res=1;
	if(s[(u-1)/m+1][(u-1)%m+1]=='.')++bcnt;
	vis[u]=true;
	for(auto v : edge[u])
	{
		if(!vis[v])res+=dfs(v);
	}
	return res;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	{
		scanf("%s",s[i]+1);
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			if(i<n && s[i][j]!=s[i+1][j])
			{
				edge[getnode(i,j)].push_back(getnode(i+1,j));
				edge[getnode(i+1,j)].push_back(getnode(i,j));
			}
			if(j<m && s[i][j]!=s[i][j+1])
			{
				edge[getnode(i,j)].push_back(getnode(i,j+1));
				edge[getnode(i,j+1)].push_back(getnode(i,j));
			}
		}
	}
	long long ans=0;
	for(int i=1;i<=n*m;++i)
	{
		if(!vis[i])
		{
			bcnt=0;
			int res=dfs(i);
			ans+=(long long)(res-bcnt)*bcnt;
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 16896
import sys
input = sys.stdin.buffer.readline

mod = 10**9+7
MAX_N = 10**7 + 10

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

k = int(input())
s = list(input())

n = len(s)-1

res = 0

for i in range(n,n+k+1):
    res = (res + (mod_comb_k(i-1,n-1,mod)*pow(25,i-n,mod)%mod)*pow(26,n+k-i,mod))%mod

print(res)

Measured memory_bytes: 385312
#!/usr/bin/env python3
def main():
    from bisect import bisect, bisect_left

    N = int(input())
    A = sorted([int(x) for x in input().split()])
    B = [int(x) for x in input().split()]
    C = sorted([int(x) for x in input().split()])

    print(sum([bisect_left(A, b) * (N - bisect(C, b)) for b in B]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 29024