akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int mod = 1000000007;
int n, m;
long long fact[N * N], invfact[N * N], dp[N][N];
long long C(int x, int y) {
	if (x < y) return 0;
	return fact[x] * invfact[y] % mod * invfact[x - y] % mod;
}
int main() {
	scanf("%d%d", &n, &m);
	if (m == 1) {puts("1"); return 0;}
	invfact[1] = 1;
	for (int i = 2; i <= n * m; i++)
		invfact[i] = (mod - mod / i) * invfact[mod % i] % mod;
	fact[0] = invfact[0] = 1;
	for (int i = 1; i <= n * m; i++)
		fact[i] = fact[i - 1] * i % mod, invfact[i] = invfact[i - 1] * invfact[i] % mod;
	dp[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			if (!i && !j) continue;
			if (i) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = 0;
			if (j) dp[i][j] = (dp[i][j] + dp[i][j - 1] * C(i + j * (m - 1) - 1, m - 2)) % mod;
		}
	}
	printf("%lld\n", dp[n][n] * fact[n] % mod);
	return 0;
}

Measured memory_bytes: 94464
import java.util.Scanner;

public class Main {
    private static StringBuilder sb;

    public static void main(String[] args) {
        init();

        String result = "TBD";
        int slash1 = sb.indexOf("/", 0);
        int slash2 = sb.indexOf("/", slash1 + 1);

        int year = Integer.parseInt(sb.substring(0, slash1));
        int month = Integer.parseInt(sb.substring(slash1 + 1, slash2));

        if (year < 2019) {
            result = "Heisei";
        } else if (year == 2019) {
            if (month <= 4) {
                result = "Heisei";
            }
        }

        System.out.println(result);
    }

    public static void init() {
        Scanner scanner = new Scanner(System.in);
        sb = new StringBuilder(scanner.next());
    }
}

Measured memory_bytes: 23124
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  let a=ts(),ans=0
  for(let i=0;i<Math.floor(a.length)/2;i++){
    if(a.length-1-i==i)break
    if(a[i]!=a[a.length-1-i])ans++
  }
  to(ans)
}
main()

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

using namespace std; 
#define fr for(int i = 0;i < n;i++)
#define pb push_back
void printVector(vector<char>x){
    for(auto i:x){
        cout << i << " ";
    }
    cout << endl;
}


int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    string str;
    cin >> str;
    int n = str.length();
    if(str[n-1] == '3') cout << "bon" << endl;
    else if(str[n-1] == '0' || str[n-1] == '1'|| str[n-1]=='6'|| str[n-1] =='8'){
        cout << "pon" << endl;
    }
    else
    {
        cout << "hon" << endl;
    }
    


}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; 

#define     int                 ll
#define     pb                  push_back
#define     mp                  make_pair
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     init(x, a)          memset(x, a, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     cpy(a,b)            memcpy(a,b,sizeof(b))
#define     is(a)               to_string(a)
#define     ci(a,c)             a-c
#define     debug(i)            cout<<"point :"<<i<<'\n';
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
    int n, sum = 0; cin>>n;
    for(int i = 1; i <=n; ++i){
    	if(i%3 && i%5) sum+=i;
    }
    cout<<sum<<'\n';
}

signed main() { 
    IO();
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}

Measured memory_bytes: 3640
// AOJ 1611: Daruma Otoshi
// 2018.1.30 bal4u

#include <stdio.h>
#include <string.h>

int w[301], d[301][301];
int dp[301][301];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, j, k, m, t;

	while (n = in()) {
		for (i = 0; i < n; i++) w[i] = in();
		for (i = 0; i < n; i++) {
			d[i][i] = 1;
			for (j = i+1; j < n; j++) {
				t = w[i] - w[j];
				d[j][i] = d[i][j] = (-1 <= t && t <= 1);
			}
		}
		memset(dp, 0, sizeof(dp));

		for (k = 2; k <= n; k++) for (i = 0; i <= n - k; i++) {
			j = i+k-1;
			if (dp[i+1][j-1] == k-2 && d[i][j]) dp[i][j] = k;
			for (m = i; m < j; m++) {
				t = dp[i][m] + dp[m+1][j];
				if (t > dp[i][j]) dp[i][j] = t;
			}
		}
		printf("%d\n", dp[0][n-1]);
	}
	return 0;
}


Measured memory_bytes: 2468
#include<iostream>

using namespace std;

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

	int i = a/k;

	if ((a <= i * k) || ((i + 1) * k <= b)) {
		cout << "OK" << endl;
	}
	else {
		cout << "NG" << endl;
	}

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
int x[100005], y[100005];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++) scanf("%d", &x[i]);
    for(int i=1;i<=m;i++) scanf("%d", &y[i]);
    LL sumx = 0, sumy = 0, tmp = 0;
    for(int i=2;i<=n;i++){
        int L = abs(x[i]-x[i-1]);
        sumx = (sumx + L*1ll*(i-1) + tmp)%mod;
        tmp = (L*1ll*(i-1) + tmp)%mod;
    }
    tmp = 0;
    for(int i=2;i<=m;i++){
        int L = abs(y[i]-y[i-1]);
        sumy = (sumy + L*1ll*(i-1) + tmp)%mod;
        tmp = (L*1ll*(i-1) + tmp)%mod;
    }
    printf("%lld\n", sumx*sumy%mod);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 

using ui64 = unsigned int64_t;
const ui64 B1 = 1000000007;
const ui64 B2 = 1000000009;
// a は b に含まれているか。ローリングハッシュ。O(al+bl)
bool contain(string a, int s, int al){
    int bl = a.size();
    int bs = s + al;
    if (al > bl) return false;

    ui64 ah1 = 0, bh1 = 0, ah2 = 0, bh2 = 0; // 最初のal文字のハッシュ値
    for(int i = 0; i < al; ++i) {
        ah1 = ah1 * B1 + a[s + i];
        bh1 = bh1 * B1 + a[bs + i];
        ah2 = ah2 * B2 + a[s + i];
        bh2 = bh2 * B2 + a[bs + i];
    }

    ui64 t1 = 1, t2 = 1;
    for (int i = 0; i < al; ++i) t1 *= B1, t2 *= B2; // B^al

    for(int i = 0; i + al <= bl; ++i){
        if (ah1 == bh1 && ah2 == bh2) return true;
        if (i + bs < bl) {
            bh1 = bh1 * B1 + a[bs + al + i] - a[bs + i] * t1;
            bh2 = bh2 * B2 + a[bs + al + i] - a[bs + i] * t2;
        }
    }
    return false;
}

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

int N;
string S;
cin >> N >> S;

i64 l = 0; // 2回以上現れる長さ
i64 r = N/2+1; // 2回以上現れない長さ。
while (r - l > 1){
    i64 len = (l + r) / 2;

    // x 以上の長さの部分文字列でSに2回以上現れるものがある。
    bool matched = false;
    rep(i, 0, N){
        if (i + len*2 > N) break;
        if (contain(S, i, len)) { // S[i:i+len] は　S[i+len:] に含まれているか。
            matched = true;
            break;
        }
    }
    if (matched) l = len;
    else r = len;
}

cout << l << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define pr pair<int,int>
	#define FR first
	#define SE second
	#define MP make_pair
	#define PB push_back
	#define vc vector
	#define mid (l+r)/2
	#define lc 2*x
	#define rc 2*x+1
	void chmax(int &x,const ll y) {x=(x>y?x:y);}
	void chmin(int &x,const ll y) {x=(x<y?x:y);}
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) putchar('-'),num=-num;
		if(num>=10) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	const int INF=0x3f3f3f3f;
	const int MOD=19491001;
	void add(ll &a,ll b){a+=b;if(a>=MOD)a-=MOD;if(a<=-MOD)a+=MOD;}
	ll qpower(ll x,ll e)
	{
		ll ans=1;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int N=1e5+10;

    void main()
	{
		int n=qread();int lst=-INF;
		for(int i=1;i<=n;i++)
		{
			int now=qread();
			if(now>=lst) ;
			else
			{
				now++;if(now<lst){puts("No");return;}
			}
			lst=now;
		}
		puts("Yes");
	}
};
int main()
{
	srand(time(0));
	mine::main();
}


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

int main(){
	ll x,y,z,k;
	cin>>x>>y>>z>>k;
	vector<ll> a(x);
	vector<ll> b(y);
	vector<ll> c(z);
	vector<ll> ans;
	for(int i=0;i<x;i++) cin>>a[i];
	for(int i=0;i<y;i++) cin>>b[i];
	for(int i=0;i<z;i++) cin>>c[i];
	sort(a.begin(),a.end(),greater<ll>());
	sort(b.begin(),b.end(),greater<ll>());
	sort(c.begin(),c.end(),greater<ll>());
	for(int i=1;i<=k;i++){
		if(i>x) continue;
		ll tmp=k/i;
		for(int j=1;j<=tmp;j++){
			if(j>y) continue;
			for(int l=1;l<=tmp/j;l++){
				if(l>z) continue;
				ans.push_back(a[i-1]+b[j-1]+c[l-1]);
			}
		}
	}
	sort(ans.begin(),ans.end(),greater<ll>());
	for(int i=0;i<k;i++) cout<<ans[i]<<endl;
	return 0;
}

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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	int n,x,t;
	cin>>n>>x>>t;

	cout<<(long long)ceil((double)n/x)*t<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

template<typename T>
bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return 1;
	}
	return 0;
}

template<typename T>
bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return 1;
	}
	return 0;
}


Measured memory_bytes: 3712
/**
 *      ABC 107 B
 *      author  : kyomukyomupurin
 *      created : 2018/08/29
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int H, W; cin >> H >> W;
    vector<vector<char> > v(H, vector<char>(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            char c; cin >> c;
            v[i][j] = c;
        }
    }

    /*for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cout << v[i][j];
        }
        cout << '\n';
    }*/

    vector<int> w;
    vector<int> h;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (v[i][j] == '#'){
                w.push_back(i);
            }
        }
    }

    for (int j = 0; j < W; ++j) {
        for (int i = 0; i < H; ++i) {
            if (v[i][j] == '#'){
                h.push_back(j);
            }
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (find(w.begin(), w.end(), i) != w.end() && find(h.begin(), h.end(), j) != h.end()){
                cout << v[i][j];             
            }         
        }
        if (find(w.begin(), w.end(), i) != w.end()){
            cout << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int A = stdIn.nextInt() ;
        long ans = 0;

        for (int i = 0; i <= A; i++) {
            if(i%3 ==0 || i%5 == 0);
            else ans += i ;
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 35916
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    int is_n = 1;
    string f = "";
    string b = "";

    for(int i = 0; i < Q; ++i){
        int T, F; char C;
        cin >> T;
        if(T == 1) is_n *= -1;
        else {
            cin >> F >> C;
            if(F == 1) {
                if(is_n == 1) f.push_back(C);
                else b.push_back(C);
            }
            else {
                if(is_n == 1) b.push_back(C);
                else f.push_back(C);
            }
        }
    }
    if(is_n == 1) {
        reverse(f.begin(), f.end());
        cout << f << S << b;
    }
    else {
        reverse(S.begin(), S.end());
        reverse(b.begin(), b.end());
        cout << b << S << f;
    }

    return 0;
}

Measured memory_bytes: 1088
import qualified Data.Vector.Unboxed as U
-- import qualified Data.Vector as V
-- import qualified Data.ByteString.Char8 as C
import Data.List
-- import Control.Monad
import Control.Arrow
--import Data.Foldable
--import Data.Char
--import qualified Data.IntMap.Strict as IM
--import qualified Data.IntSet as IS
-- import Data.Sequence as Sq

-- r :: Int -> IO (U.Vector Int)
-- r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

-- r' :: IO [Int]
-- r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine




main = do
    n <- readLn :: IO Int
    s <- U.fromList <$> getLine
    let x = length $ filter id [ f dist from s | from<-[0..n-3], dist<-[1..n-(div from 3)]]
    let r = c 'R' s
    let g = c 'G' s
    let b = n - r - g
    print $ r*g*b - x

f :: Int -> Int -> U.Vector Char -> Bool
f dist from v
    | from+2*dist >= U.length v = False
    | otherwise = "BGR" == (sort $ map ((v U.!).(+from)) [0,dist,2*dist] )

c x = U.length . U.filter (==x)


Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
 
//#define USING_LONG_LONG
#ifdef USING_LONG_LONG
    #define int long long
    const int INF=1001001001001001001ll;
#else
    const int INF=1001001001;
#endif
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREP(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define clr(a) memset((a),0,sizeof(a))
#define CLR(a) memset((a),-1,sizeof(a))
#define each(i,v) for(__typeof((v).begin()) i=(v).begin();i!=(v).end();i++)
#define minv(a,b) (a)=min((a),(b))
#define maxv(a,b) (a)=max((a),(b))
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<string>vs;
typedef pair<int,int>pii;
#define fi first
#define se second
 
int N,X,M;
int l[10],r[10],s[10];
int ans[6],ma,latte[6];
 
void check(){
    int xxx=0;
    rep(i,M){
        int sum=0;
        for(int j=l[i];j<=r[i];j++)sum+=latte[j];
        if(sum!=s[i])return;
    }
    rep(i,N)xxx+=latte[i];
    if(xxx>ma){
        rep(i,N)ans[i]=latte[i];
        ma=xxx;
    }
}
 
void dfs(int t){
    if(t==N){
        check();return;
    }
 
    rep(i,X+1){
        latte[t]=i;
        dfs(t+1);
    }
}
 
signed main(){
    cin>>N>>X>>M;
    rep(i,M)cin>>l[i]>>r[i]>>s[i],l[i]--,r[i]--;
 
    ma=-1;
    dfs(0);
    if(ma==-1)cout<<-1<<endl;
    else{
        rep(i,N){
            if(i)cout<<" ";
            cout<<ans[i];
        }
        cout<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 3052
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s = iterator.next().unwrap().chars().collect::<Vec<char>>();

    let mut part = Vec::new();

    let mut ans: Vec<usize> = Vec::with_capacity(s.len());

    let n = s.len();
    for i in 0..n {
        part.push(s[i]);
        if i >= n - 1 || (s[i] == 'L' && s[i + 1] == 'R') {
            let mut a = calc(&part);
            ans.append(&mut a);
            part = Vec::new();
        }
    }

    return ans.iter().map(|num| num.to_string()).collect::<Vec<_>>().join(" ");
}

fn calc(part: &Vec<char>) -> Vec<usize> {
    let l_position = part.iter().position(|&ch| ch == 'L').unwrap();
    let l_count = part.len() - l_position;
    let r_count = part.len() - l_count;

    let mut result = vec![0; part.len()];
    result[l_position - 1] = (r_count + 1) / 2 + l_count / 2;
    result[l_position] = r_count / 2 + (l_count + 1) / 2;
    result
}


Measured memory_bytes: 10492
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    ans = [0]

    def dfs(num):
        if not num or num and int(''.join(num)) <= N:
            if num.count('7') >= 1 and num.count('5') >= 1 and num.count('3') >= 1:
                ans[0] += 1
            for i in ('7', '5', '3'):
                num.append(i)
                dfs(num)
                num.pop()

    dfs([])
    
    print(ans[0])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10120
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int MOD = 100000000 + 7;

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

    int n;
    cin >> n;

    for (int i = 0; i < 2; i++)
    {
        for (int j = 10 - 1; j >= 2; j--)
        {
            if (n % j == 0)
            {
                n /= j;
                break;
            }
        }
    }

    cout << (n == 1 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000009
#define int long long
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int pow(int p,int r){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%mod)*(p%mod))%mod;
	 }
	 r=r>>1;
     p=((p%mod)*(p%mod))%mod;
	}
	return ans;
}
signed main() {
	 garou;
	int k,a,b;
	cin>>k>>a>>b;
	int x=(b/k)*k;
	if(x<=b&&x>=a)
	cout<<"OK";
	else
	{
		cout<<"NG";
	}
	 
}

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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  int N;
  cin >> N;
  vi d(N);
  rep(i, N) cin >> d[i];

  int res = 0;
  rep(i, N - 1) FOR(j, i + 1, N) res += d[i] * d[j];

  cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int isprime(long long x){
	int a, i;
	if(x == 2){
		return 1;
	}else if(x < 2 || x%2 == 0){
		return 0;
	}
	i = 3;
	while(i <= sqrt(x)){
		if(x%i == 0){
			return 0;
		}
		i = i + 2;
	}
	return 1;
}

int main(void){
	long long a;
	int b=0, n, i;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &a);
		if(isprime(a) == 1){
			b++;
		}
	}
	printf("%d\n", b);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	char str[200008];
	cin>>str;
	int l = strlen(str);
	int al[200008], ar[200008], ans[200009];
	ar[0] = 1;

	for (int i = 0; i < l-1; ++i)
  	{
  		ans[i] = 0;
		if( str[i] == 'R')
		{
			ar[i] = ar[i-1] + 1;
			ar[i-1] = 0;
		}
		else
			ar[i] = 0;
  	}
  	for (int i = l-1; i > 0; i--)
  	{
		
		if( str[i] == 'L')
		{
			al[i] = al[i+1] + 1;
			al[i+1] = 0;
		}
		else
			al[i] = 0;
  	}
  	for (int i = 0; i < l; ++i)
  	{
  		if(ar[i] > 0)
  		{
  			ans[i] += ar[i] - (ar[i]/2);
  			ans[i+1] += ar[i]/2;
  		}
  		if(al[i] > 0)
  		{
  			ans[i] += al[i] - (al[i]/2);
  			ans[i-1] += al[i]/2;
  		}	
  	}
  	for (int i = 0; i < l-1; ++i)
  	{
  		cout<< ans[i]<<" ";
  	}
  	cout<<ans[l-1]<<endl;
  	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	set<string> st;
	int n;
	cin >> n;
	rep (i, n) {
	  string s;
	  cin >> s;
	  st.insert(s);
	}
	cout << st.size() << endl;
    
    return 0;
}



Measured memory_bytes: 19248
package main

import (
        "fmt"
)

func main() {
        var a int
        var b int
        var c int
        fmt.Scan(&a)
        fmt.Scan(&b)
        fmt.Scan(&c)
        d := b / a
        if d > c {
                fmt.Print(c)
        } else {
                fmt.Print(d)
        }
}

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

int main(){
	vector<string> s(3);
	for(int i=0; i<3; i++){
		cin >> s.at(i);
	}
	string ans;
	string sam="abcdefghijklmnopqrstuvwxyz";
	string res="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for(int i=0; i<3; i++){
		for(int j=0; j<26; j++){
			if(s.at(i).at(0)==sam.at(j)) ans+=res.at(j);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3588
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        dp[0] = 0;

        for (int i = 1; i < n; i++) {
            for (int j=Math.max(i - k, 0); j < i; j++) {
                dp[i] = Math.min(dp[i], dp[j] + Math.abs(heights[i] - heights[j]));
            }
        }
        System.out.println(dp[n - 1]);
    }
}

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 510000;
const int MOD = 1e9+7;

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;
  cin >> n >> a >> b;
  ll ans=0;
  ans+=modpow(2,n,mod);
  ans+=mod-1;
  ans%=mod;
  ll temp=1;
  rep(i,a){
    temp*=inv[i+1];
    temp%=mod;
  }
  for(int i=n;i>=n-a+1;i--){
    temp*=i;
    temp%=mod;
  }
  ll temp2=1;
  rep(i,b){
    temp2*=inv[i+1];
    temp2%=mod;
  }
  for(int i=n;i>=n-b+1;i--){
    temp2*=i;
    temp2%=mod;
  }
  ll temp3=mod-temp;
  temp3%=mod;
  temp3+=(mod-temp2);
  temp3%=mod;
  ans+=temp3;
  ans%=mod;
  cout << ans << endl;
return 0;}

Measured memory_bytes: 12160
A = list(input())
 
l = [0, 0, 0]
 
for i in range(len(A)):
  if A[i] == 'a':
    l[0] = 1
  elif A[i] == 'b':
    l[1] = 1
  else:
    l[2] = 1
    
if l[0] == 1 and l[1] == 1 and l[2] == 1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
import java.util.*;

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

   Scanner scanner = new Scanner(System.in);
		int x=scanner.nextInt();
		int ans = 0;
		int count = 0;
		for(;ans < x;count++){
			ans += count;
		}
		System.out.println(count-1);
    
  }   
}


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

using namespace std;


int main() {
    int R, G, B, N;
    int r, g, b, nr, ng;
    int res = 0;

    cin >> R >> G >> B >> N;

    r = N / R;

    for (int i = r; i >= 0; i--) {
        nr = N - (R * i);
        g = nr / G;
        for (int j = g; j >= 0; j--) {
            ng = nr - (G * j);
            b = ng % B;
            if (b == 0) {
                res++;
            }
        }
    }

    cout << res;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <cstring>
using namespace std;

int m, n;
string s;

int main() {
	scanf("%d %d", &m, &n);
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> s;
			if (s == "snuke") {
				printf("%c", 'A' + j - 1);
				printf("%d\n", i);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
s = input()
if s[0] == s[1] == s[2] == s[3]:
    print('No')
elif (s[0] == s[1] and s[2] == s[3]) or (s[0] == s[2] and s[1] == s[3]) or (s[0] == s[3] and s[1] == s[2]):
    print("Yes")
else:
    print('No')


Measured memory_bytes: 9064
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    

    ll n;
    cin >> n;
    ll flag = 0;
    vector <ll> v;
    for (ll i=0;i<n;i++){
        ll p;
        cin >> p;
        if(p > i){
            cout << - 1 << endl;
            flag = 1;
            break;
        }
        if(i > 0 and p-v[i-1] > 1){
            cout << -1 << endl;
            flag = 1;
            break;
        }
        v.push_back(p);

    }
    if(flag == 0){
        ll ans = 0;
        reverse(v.begin(), v.end());
        ans += v[0];
        for (ll i=1;i<n;i++){
            if(v[i-1] > v[i]){
                continue;
            }
            ans += v[i];
        }
        cout << ans << endl;
    }


}




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

int main(){

    ll n;
    cin >> n;

    vector<ll> x(n),y(n),t(n+1);
    rep(i,n) cin >> t[i] >> x[i] >> y[i];
    ll nx=0,ny=0,nt=t[0];
    for(int i=0;i<n;i++){
        ll d=abs(x[i]-nx)+abs(y[i]-ny);
        if(d%2!=nt%2||d>nt){
            cout << "No" << endl;
            return 0;
        }
        nx=x[i];
        ny=y[i];
        nt=t[i+1]-t[i];
    }
    cout << "Yes" << endl;

    return 0;
}

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

long long N,X;
long long T[50];
long long P[50];

long long countpati(long long N,long long X){
  if(X==1){
    if(N==0){
      return 1;
    }
    else return 0;
  }
  if(1<X && X<=1+T[N-1]){
    return countpati(N-1,X-1);
  }
  if(X==2+T[N-1]){
    return 1+P[N-1];
  }
  if(2+T[N-1]<X && X<=2+2*T[N-1]){
    return P[N-1]+1+countpati(N-1,X-2-T[N-1]);
  }
  if(X==3+2*T[N-1]){
    return 2*P[N-1]+1;
  }
}



int main(){

  cin>>N>>X;
  
  T[0]=1;
  P[0]=1;
  for(int i=0;i<=48;i++){
    T[i+1]=T[i]*2+3;
    P[i+1]=P[i]*2+1;
  }
  
  long long ans=countpati(N,X);
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3628
n=int(input())
a=[0]*n
x=[[]*n for i in range(n)]
for i in range(n):
    a[i]=int(input())
    for ii in range(a[i]):
        xi,yi=map(int,input().split())
        x[i].append([xi-1,yi])
        
import itertools
ans=0
for i in itertools.product([0,1], repeat=n):
    yn=""
    for j in range(n):
#        print(i,j,"-----------------")
        if i[j]==1:
            for xx in x[j]:
#                print(i[xx[0]]==xx[1],xx)
                if i[xx[0]]!=xx[1]:
                    yn="No"
                    break
#    print(i,"yn:",yn)
    if yn!="No":
        ans=max(ans,sum(i))

print(ans)
    

Measured memory_bytes: 3064
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;

void main() {
    int N = readln.chomp.to!int;
    auto cards = readln.chomp.split;
    auto cards2 = cards.dup;
    string b = cards.bubbleSort.join(" ");
    b.writeln;
    "Stable".writeln;
    string s = cards2.selectionSort.join(" ");
    s.writeln;
    writeln(s == b ? "Stable" : "Not stable");
}

string[] bubbleSort(string[] cc) {
    string[] c = cc;
    auto n = c.length;
    for (int i = 0; i < n - 1; i++) {
        for (int j = n.to!int - 1; j > i; j--) {
            if (c[j][1] < c[j - 1][1]) {
                swap(c[j], c[j - 1]);
            }
        }
    }

    return c;
}

string[] selectionSort(string[] cc) {
    string[] c = cc;
    auto n = c.length;
    for (int i = 0; i < n - 1; i++) {
        int minv = c[i][1];
        int minj = i;

        for (int j = i + 1; j < n; j++) {
            if (minv > c[j][1]) {
                minv = c[j][1];
                minj = j;
            }
        }

        swap(c[i], c[minj]);
    }

    return c;
}

Measured memory_bytes: 1064
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;	
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) {
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}

template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
int modulo = 1e9 + 7;

int fpow(int a, int n) {
	int ans = 1;
	while (n) {
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n; cin >> n;
	multiset <double> s;
	For(i,0,n) {
		double x; cin >> x;
		s.insert(x);
	}
	double ans;
	while (s.size() > 1) {
		double a = *s.begin(); s.erase(s.begin());
		double b = *s.begin(); s.erase(s.begin());
		ans = (a+b)/2;
		s.insert(ans); 
	}
	cout << fixed << setprecision(9) << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const int mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%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;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

mint modpow(long long a, long long n){
  long long r = 1;
  while (n) {
    r = r * ( (n%2)?a:1 ) %mod;
    a = a * a % mod;
    n >>= 1;
  }
  return r;
}

int main(void){
    ll n,m,k;cin>>n>>m>>k;
    mint res=0;
    combination c(n+10);
    rep(i,k+1){
        ll buf=n-i;
        mint buf3=(mint)m*modpow(m-1,buf-1)*c(n-1,n-1-i);
        res+=buf3;
    }
    cout<<res.x<<endl;
}

Measured memory_bytes: 6344
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

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

using namespace std;

const int MOD = 1000 * 1000 * 1000 + 7;
using Mat = vector<vector<int>>;

Mat mul(const Mat& u, const Mat& v) {
    int n = u.size();
    Mat res(n);
    for (auto& v : res) {
        v.resize(n);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                res[i][j] = (res[i][j] + 1ll * u[i][k] * v[k][j]) % MOD;
            }
        }
    }

    return res;
}

const int LG = 61;

Mat pw[LG];

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n;
    ll k;
    cin >> n >> k;
    pw[0].resize(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int x;
            cin >> x;
            pw[0][i].push_back(x);
        }
    }

    for (int i = 1; i < LG; i++) {
        pw[i] = mul(pw[i - 1], pw[i - 1]);
    }

    Mat res(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) {
                res[i].push_back(1);
            } else {
                res[i].push_back(0);
            }
        }
    }

    for (int i = LG - 1; i >= 0; i--) {
        if ((1ll << i) <= k) {
            res = mul(res, pw[i]);
            k -= (1ll << i);
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            ans = (ans + res[i][j]) % MOD;
        }
    }

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



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

using namespace std;

struct Node {
	int key, pri;
	Node *left, *right;
};

Node *root, *NIL;

Node* rightRotate(Node* t) {
	Node* s = t->left;
	t->left = s->right;
	s->right = t;
	if (t == root)
	  root = s;
	return s;
}

Node* leftRotate(Node* t) {
	Node* s = t->right;
	t->right = s->left;
	s->left = t;
	if (t == root)
	  root = s;
	return s;
}

void inorder(Node *t) {
	if (t == NIL)
		return;
	inorder(t->left);
	cout << " " << t->key;
	inorder(t->right);
}

void preorder(Node *t) {
	if (t == NIL)
		return;
	cout << " " << t->key;
	preorder(t->left);
	preorder(t->right);
}

void status(Node* t) {
	cout << "k:" << t->key << endl;
	cout << "l:" << t->left << endl;
	cout << "r:" << t->right << endl;
	cout << endl;
}

Node* insert(Node *t, int key, int pri) {
	if (t == NIL) {
		Node *u = new Node();
		u->key = key;
		u->pri = pri;
		u->left = u->right = NIL;
		return u;
	}
	if (key == t->key) {
		return t;
	}

	if (key < t->key) {
		t->left = insert(t->left, key, pri);
		if (t->pri < t->left->pri)
			t = rightRotate(t);
	}
	else {
		t->right = insert(t->right, key, pri);
		if (t->pri < t->right->pri)
			t = leftRotate(t);
	}

	return t;
}

Node* find(Node* t, int key) {
	if (t == NIL)
		return NIL;
	if (key == t->key)
		return t;

	Node* u;
	if (key < t->key) {
		if ((u = find(t->left, key)) != NIL)
			return u;
	}
	else {
		if ((u = find(t->right, key)) != NIL)
			return u;
	}
	return NIL;
}

Node* _delete(Node *t, int key);

Node* nodeDelete(Node *t, int key) {
	if (t == NIL)
		return NIL;
	if (key < t->key)
		t->left = nodeDelete(t->left, key);
	else if (key > t->key)
		t->right = nodeDelete(t->right, key);
	else
		return _delete(t, key);
	return t;
}

Node* _delete(Node *t, int key) {
	if (t->left == NIL && t->right == NIL) {
		return NIL;
	}
	else if (t->left == NIL) {
		t = leftRotate(t);
	}
	else if (t->right == NIL) {
		t = rightRotate(t);
	}
	else {
		if (t->left->pri > t->right->pri) {
			t = rightRotate(t);
		}
		else {
			t = leftRotate(t);
		}
	}
	return nodeDelete(t, key);
}

int main() {
	int m, k, p;
	string s;

	NIL = new Node();
	NIL->left = NIL->right = NIL;
	root = NIL;

	cin >> m;
	while (m--) {
		cin >> s;
		if (s == "insert") {
			cin >> k >> p;
			Node *t = insert(root, k, p);
			if (root == NIL) {
				root = t;
			}
		}
		else if (s == "find") {
			cin >> k;
			cout << ((find(root, k) == NIL) ? "no" : "yes") << endl;
		}
		else if (s == "delete") {
			cin >> k;
			nodeDelete(root, k);
		}
		else if (s == "print") {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 9412
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define pii pair <int,int>
#define vpii vector< pair<int,int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
ll findlcm(ll arr[], ll n, ll m) 
{ 
    ll ans = arr[0]; 
    for (int i = 1; i < n; i++){
    	ans = (((arr[i] * ans)) / (__gcd(arr[i], ans))); 
    	if(ans > 2 * m) 
		return -1;
	}
    return ans; 
} 
int main()
{
	boost;
	ll n, m, i;
	cin >> n >> m;
	ll arr[n];
	vector <ll> v;
	fo(i, 0, n){
		cin >> arr[i];
		ll x = arr[i];
		ll cnt = 0;
		while(x % 2 == 0){
			x /= 2;
			cnt++;
		}
		v.pb(cnt);
	}
	ll mx = *max_element(all(v));
	ll mn = *min_element(all(v));
	if(mx != mn)
	cout << 0;
	else{
		ll strt = findlcm(arr, n, m);
		if(strt == -1) cout << 0;
		else{
			strt /= 2;
			cout << 1 + (m - strt) / (2 * strt);
		}
	}
}

Measured memory_bytes: 1912
from collections import deque

class UnionFind():
  def __init__(self, n):
    self.seg_tree = [-1 for i in range(n)]
  
  def root(self, i):
    if self.seg_tree[i] < 0:
      return i
    else:
      self.seg_tree[i] = self.root(self.seg_tree[i])
      return self.seg_tree[i]

  def size(self, i):
    return -self.seg_tree[self.root(i)]

  def unite(self, i, j):
    if self.same(i, j):
      return

    if self.size(i) == self.size(j):
      self.seg_tree[self.root(i)] -= self.size(j)
      self.seg_tree[self.root(j)] = self.root(i)
    elif self.size(i) > self.size(j):
      self.seg_tree[self.root(i)] -= self.size(j)
      self.seg_tree[self.root(j)] = self.root(i)
    else:
      self.seg_tree[self.root(j)] -= self.size(i)
      self.seg_tree[self.root(i)] = self.root(j)

  def same(self, i, j):
    return self.root(i) == self.root(j)

N, M = map(int, raw_input().split())
AB = [map(long, raw_input().split()) for _ in range(M)]

uf = UnionFind(N)
rev_res = []

ans = N * (N - 1) / 2
for a, b in reversed(AB):
  rev_res.append(ans)
  if not uf.same(a - 1, b - 1):
    ans -= uf.size(a - 1) * uf.size(b - 1)
  uf.unite(a - 1, b - 1)

for r in reversed(rev_res):
  print r

Measured memory_bytes: 27320
#include <bits/stdc++.h>
using namespace std;
int n,m;
int k,x,fa;
int f[100005];
int vis[100005];
int find(int x)
{
	if(x==f[x])
		return x;
	return f[x]=find(f[x]);
}
int main() {
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		f[i]=i;
	}
	while(n--)
	{
		scanf("%d",&k);
		scanf("%d",&x);
		fa=find(x);
		vis[x]=1;
		for(int i=1;i<k;i++)
		{
			scanf("%d",&x);
			vis[x]=1;
			f[find(x)]=fa;
		}
	}
	fa=find(x);
	for(int i=1;i<=m;i++)
	{
		if(vis[i]&&find(i)!=fa)
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bs binary_search
#define pb push_back
#define pp pair<ll,ll>
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
int main() 
{
    fastio
    ll a,b,n,x; cin>>a>>b>>n;
    x=min(n,b-1);
    cout<<((a*x)/b-a*(x/b));
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  ll a,now1=0,cnt1=0,now2=0,cnt2=0;
  rep(i,n) cin >> A[i];
  rep(i,n) {
    now1 += A[i];
    now2 += A[i];
    if (now1<=0) {
      cnt1+=abs(now1)+1;now1=1;
    }
    if (now2>=0) {
      cnt2+=abs(now2)+1;now2=-1;
    }
    swap(now1,now2);swap(cnt1,cnt2);
  }
  cout << min(cnt1,cnt2) << endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var XYZ = Console.ReadLine().Split().Select(int.Parse).ToList();

            // ab swap
            // ac swap

            Console.WriteLine($"{XYZ[2]} {XYZ[0]} {XYZ[1]}");

        }
    }
}


Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main(){
    int num1, num2, num3;
    cin >> num1 >> num2 >> num3;
    if(num1 < num2 && num2 < num3 && num1 < num3){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1156