akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cmath>
#include <iostream>
using namespace std;

int isqrt(long long n) {
    int lb = 0, ub = 1<<30;
    while (ub - lb > 1) {
        int m = (lb + ub) / 2;
        if ((long long)m*m <= n) lb = m;
        else ub = m;
    }
    return lb;
}

int main() {
    int q; cin >> q;
    while (q--) {
        int a, b; cin >> a >> b;
        long long C = (long long)a*b - 1;
        long long c = isqrt(C);
        if (a < b) swap(a, b);
        bool incl_c = c*(c+1) <= C;
        int ans = 2*c;
        if (c >= b) ans--;
        if (!incl_c) { assert (c < a); c--; ans--; }
        long long x0 = incl_c ? c + 1 : c + 2;
        // cerr << c << ' ' << x0 << endl;
        if ((c - a + x0) * (a + 1) > C) ans--;
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
for($i = 0; $i < $N; $i++){
    fscanf(STDIN, "%d%d", $a[], $b[]);
}

for($i = 0; $i < $N; $i++){
    fscanf(STDIN, "%d%d", $c[], $d[]);
}
array_multisort($c, SORT_ASC, $d);

$ok = 0;
for($i = 0; $i < $N; $i++){//cd
    $maxY = -100;
    $maxJ = -1;
    foreach($a as $j => $_){//ab
        if($a[$j] < $c[$i] && $b[$j] < $d[$i]){
            if($maxY < $b[$j]){
                $maxY = $b[$j];
                $maxJ = $j;
            }
        }
    }
    if($maxJ != -1){
        unset($a[$maxJ]);
        unset($b[$maxJ]);
        $ok++;
    }
}
echo $ok;


Measured memory_bytes: 4728
import sys
input=sys.stdin.readline

def dijkstra(s,n,Cost):
    D=[float('inf')]*n
    Visited=[False]*n
    D[s]=0
    while True:
        v=-1
        for i in range(n):
            if (not Visited[i]) and v==-1:
                v=i
            elif (not Visited[i]) and D[i]<D[v]:
                v=i
        if v==-1:
            break
        Visited[v]=True
        for j in range(n):
            D[j]=min(D[j],D[v]+Cost[v][j])
    return D

def dist(V1,V2):
    return max(0,((V2[0]-V1[0])**2+(V2[1]-V1[1])**2)**0.5-(V1[2]+V2[2]))

sx,sy,gx,gy=map(int,input().split())
n=int(input())
V=[(sx,sy,0)]+[tuple(map(int,input().split())) for _ in range(n)]+[(gx,gy,0)]
Cost=[[float('inf')]*(n+2)for _ in range(n+2)]
for i in range(n+1):
    for j in range(i,n+2):
        d=dist(V[i],V[j])
        Cost[i][j]=d; Cost[j][i]=d
print(dijkstra(0,n+2,Cost)[-1])

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	string s;
	cin>>n>>s;
	s='-'+s;
	vector<int>r(1,0),g(1,0);
	vector<bool>B(s.size()+1,false);
	int b=0;
	for(int i=1;i<s.size();++i){
		if(s.at(i)=='R'){
			r.emplace_back(i);
		}else if(s.at(i)=='G'){
			g.emplace_back(i);
		}else{
			++b;
			B.at(i)=true;
		}
	}
	uint64_t ans=0;
	for(int i=1;i<r.size();++i){
		for(int j=1;j<g.size();++j){
			int minnum=min(r.at(i),g.at(j)),
			mxnum=max(r.at(i),g.at(j));
			
			int sa=abs(r.at(i)-g.at(j));

			int blow=minnum-sa, bmid=(r.at(i)+g.at(j))/2,
			bhigh=mxnum+sa;
			ans+=b;
			if(blow>=0&&B.at(blow))--ans;
			if(B.at(bmid)&&mxnum-bmid==bmid-minnum)--ans;
			if(bhigh<s.size()&&B.at(bhigh))--ans;
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 3624
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int n,m;
  cin>>n>>m;
  if(m<n*2){
    cout<<m/2<<endl;
  }else{
    int rest=m-2*n;
    cout<<(n+rest/4)<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll max_val(ll wt[],ll val[],ll n,ll w){

	ll dp[n+1][w+1];
	for(ll i=0;i<=n;++i){
		for( ll j=0;j<=w;++j){
			if(i==0 || j==0){
				dp[i][j]= 0;
			}
			else if(j >= wt[i-1]){
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-wt[i-1]] + val[i-1]);
			}
			else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}

	return dp[n][w];
}


int main(){

	ll N,W;
	cin>>N>>W;
	ll wt[N],val[N];
	for(ll i=0;i<N;++i){
		cin>>wt[i] >> val[i];
	}

	cout << max_val(wt,val,N,W);



	return 0;
}

Measured memory_bytes: 79104
// ABC161B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	int all = 0;
	int a[1010] = {};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		all += a[i];
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i]*4*m >= all) cnt++; // 移項して除算を使わない
	}
	if (cnt >= m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

using namespace std;

#define ll long long

int main()
{
    int t;
    cin>>t;
    int a[t],z=0;
    for(int i=0;i<t;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<t-2;i++)
    {
        for(int j=i+1;j<t-1;j++)
        {
            for(int k=j+1;k<t;k++)
            {
                int b[3];
                b[0]=a[i];
                b[1]=a[j];
                b[2]=a[k];
                sort(b,b+3);
                if(b[0]+b[1]>b[2] && a[i]^a[j] && a[i]^a[k] && a[j]^a[k])
                {
                    z++;
                    //cout<<i+1<<" "<<j+1<<" "<<k+1<<"\n";
                }
            }
        }
    }
    cout<<z;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

// 削除はできない
class Median {
private:
    priority_queue<ll> former;
    priority_queue<ll,vector<ll>,greater<ll>> latter;
public:
    Median();
    void add(ll x);
    ll get();
    ~Median();
};

Median::Median() {
}

// add a number into data structure
void Median::add(ll x) {
    // どちらに入る？
    if (former.empty()) {
        former.push(x);
    }
    else {
        ll former_top = former.top();
        if (former_top < x) latter.push(x);
        else former.push(x);
    }

    // 数を合わせる
    // when latter has one more element
    if ((int)latter.size() == (int)former.size()+1) {
        ll tmp = latter.top(); latter.pop();
        former.push(tmp);
    }
    // when former has two more elements
    else if ((int)(former.size()) == (int)latter.size()+2) {
        ll tmp = former.top(); former.pop();
        latter.push(tmp);
    }
    else if ((int)former.size() == (int)latter.size() || (int)former.size() == (int)latter.size()+1) {}
    else {
        cout << "I don't believe this situation" << '\n';
        cout << "the size of former is " << former.size() << '\n';
        cout << "and the size of latter is " << latter.size() << '\n';
        exit(0);
    }
}

// get the median
ll Median::get() {
    return former.top();
}

Median::~Median() {
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    Median med;
    vector<ll> x;
    rep(i,n) {
        ll a; cin>>a;
        x.push_back(a);
        med.add(a-(i+1));
    }
    ll b = med.get();
    ll ans = 0;
    rep(i,n) {
        ans += abs((x[i]-(i+1))-b);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4596
from collections import deque

def solve(s):
    dq = deque()
    for i in range(len(s)):
        if   s[i]=='(':dq.append(s[i])
        elif s[i]=='[':dq.append(s[i])
        elif s[i]==')':
            if len(dq)==0:return ('no')
            a = dq.pop()
            if a!='(':return ('no')
        elif s[i]==']':
            if len(dq)==0:return ('no')
            a = dq.pop()
            if a!='[':return ('no')
    if len(dq)==0:return ('yes')
    return ('no')

def main():
    while True:
        s = input()
        if s == '.':break
        print (solve(s))


if __name__ == '__main__':
    main()




Measured memory_bytes: 5964
'use strict'

function main(input) {
  input = input.split(' ').map(v => ~~v)

  let ans = 'No'
  if (input[0] <= input[2] && input[2] <= input[1]) {
    ans = 'Yes'
  }

  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 21192
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
class BIT {
    private:
        int size_;
        vector<int> bit;
    public:
        BIT() {
            size_ = 500000;
            bit = vector<int>(500010, 0);
        }
        BIT(int size__) {
            size_ = size__;
            bit = vector<int>(500010, 0);
        }
        int sum(int i) {
            int ret = 0;
            while(i > 0) {
                ret += bit[i];
                i -= i & (-i);
            }
            return ret;
        }
        void add(int i, int x) {
            while(i <= size_) {
                bit[i] += x;
                i += i & (-i);
            }
        }
};


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;
    BIT bit[26];
    rep(i, N) {
        bit[S[i] - 'a'].add(i + 1, 1);
    }
    int Q; cin >> Q;
    while(Q--) {
        int q; cin >> q;
        if(q == 1) {
            int x; char c;
            cin >> x >> c;
            x--;
            bit[S[x] - 'a'].add(x + 1, -1);
            S[x] = c;
            bit[S[x] - 'a'].add(x + 1, 1);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            int ans = 0;
            rep(i, 26) {
                if(bit[i].sum(r) - bit[i].sum(l) >= 1) ans++;
            }
            cout << ans << endl;
        }
    }
    

    return 0;
}


Measured memory_bytes: 54660
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int cnt = 0;
  REP(i,3){
    char a;
    cin >> a;
    if(a == '1') cnt++;
  }
  cout << cnt << endl;
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

string keys[10] = {
    "",
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};

int main()
{
    int n;
    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        string ans = "";
        int cnt = 0;
        int d = 0;
        rep(j, s.size()) {
            if(s[j]=='0') {
                if(d==0||cnt==0) continue;
                if(d==1) cnt = (cnt-1)%5;
                else if(d==7||d==9) cnt = (cnt-1)%4;
                else cnt = (cnt-1)%3;
                ans += keys[d][cnt];
                cnt = 0;
                d = 0;
            }
            else {
                d = s[j] - '0';
                cnt++;
            }
        }
        P(ans);
    }
    return 0;
}

Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
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; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

	int k, t;
	cin >> k >> t;

	vector<int> a(t);

	rep(i, t) {
		cin >> a[i];
	}

	sort(a.begin(), a.end(), greater<>());

	ll ans;
	ans = max(a[0] - 1 - (k - a[0]), 0);

	cout << ans;

	return 0;
}


ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

Measured memory_bytes: 3640
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF=100000001,ID_MAX=20;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}

const int N_MAX=1001;
char s[N_MAX],t[N_MAX];
int dp[N_MAX][N_MAX];

int rec(int i,int j){
    if(dp[i][j]>=0){
        return dp[i][j];
    }
    int res;
    if(i==0){
        res=j;
    }else if(j==0){
        res=i;
    }else if(s[i-1]==t[j-1]){
        res=rec(i-1,j-1);
    }else{
        res=min({rec(i-1,j),rec(i,j-1),rec(i-1,j-1)})+1;
    }
    return dp[i][j]=res;
}

int main(){
    int i;
    //入力
    cin>>s;
    cin>>t;
    //処理
    memset(dp,-1,sizeof(dp));
    //出力
    cout<<rec(strlen(s),strlen(t))<<endl;
}


Measured memory_bytes: 7112
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect 

const int N = 1e5 + 7, INF = 1e9 + 7;

int x[N], y[N], c[N];

void solve() {
    int a, b, m, ma = INF, mb = INF, ans; cin >> a >> b >> m;
    loop1(i, a) {
        cin >> x[i];
        ma = min(ma, x[i]);
    }
    loop1(i, b) {
        cin >> y[i];
        mb = min(mb, y[i]);
    }
    ans = ma + mb;
    loop(i, m) {
        int v, u, s;
        cin >> v >> u >> s;
        ans = min(ans, x[v] + y[u] - s);
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

int divisors(int n)
{
    int ret = 0;
    for (int i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            ret++;
            if (n / i != i)
                ret++;
        }
    }
    return ret;
}

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

    int ans = 0;
    rep (i, n + 1)
        if (divisors(i) == 8 && i % 2 == 1)
            ans++;

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

Measured memory_bytes: 3608
import sys
import itertools
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    ans=0
    l=['7','5','3']
    for k in range(3,len(str(N))+1):
        for i in range(3**k):
            x=[]
            for j in range(k):
                x+=l[(i//(3**j))%3]
            if '7' in x and '5' in x and '3' in x:
                x=int(''.join(x))
                if x <= N: ans+=1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 42476
# これ問題の意味がわかりにくくない？
import fractions
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
diff = [abs(i-M) for i in X]
max_gcd = diff[0]
for i in range(1, len(diff)):
  max_gcd = fractions.gcd(diff[i], max_gcd)
print(max_gcd)

Measured memory_bytes: 16280
from functools import lru_cache
mod=1000000007

m,n=[int(i) for i in input().split(" ")]

@lru_cache()
def power(m,n,mod):
    if n==0:
        return 1
    elif n==1:
        return m
    elif n%2==0:
        return ((power(m,n//2,mod)%mod) * (power(m,n//2,mod)%mod))%mod
    else:
        return (power(m,n-1,mod)*m)%mod

print(power(m,n,mod))



Measured memory_bytes: 6300
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j, k, l;
	long int m1, d1, m2, d2;
	
	scanf("%ld%ld%ld%ld", &m1, &d1, &m2, &d2);
	
	if(m1 == m2) {
		printf("0\n");
	} else {
		printf("1\n");
	}
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}




void oneCase () {
    int w, a, b;
    cin >> w >> a >> b;
    cout << max(0, abs(a - b) - w) << "\n";
}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

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

int main()
{
    int W, H;
    while (cin >> H >> W)
    {
        if (H == 0 && W == 0)
            break;
        for (int row = 0; row < H; ++row)
        {
            for (int col = 0; col < W; ++col)
                cout << '#';
            cout << "\n";
        }
        cout << "\n";
    }
}


Measured memory_bytes: 3096
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
    a[i] -= 1

rail = [-1]*n

x = a[0]
rail[0] = 0
kasanari = -1
for i in range(10**6):
    if rail[x] == -1:
        rail[x] = i+1
        x = a[x]
    else:
        y = rail[x]
        oneroop = (i+1) - y
        break
        
if y >= k:
    for i in range(n):
        if rail[i] == k:
            print(i+1)
            
else:
    kk = (k-y) % oneroop + y
    for i in range(n):
        if rail[i] == kk:
            print(i+1)

Measured memory_bytes: 92308
#include"bits/stdc++.h"

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int A, B;
	cin >> A >> B;
	for (int i = 0; i < 1010; i++){
		if (floor(i * 0.08) == A && floor(i * 0.1) == B) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
	"strings"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	rr := make([]*big.Rat, n)
	for i := 0; i < n; i++ {
		s := getNextString(scanner)
		rr[i] = strtorat(s)
	}
	num2 := make([]int, n)
	num5 := make([]int, n)
	denom2 := make([]int, n)
	denom5 := make([]int, n)

	nd := makeGrid(64, 64)

	var ans int64
	for i := 0; i < n; i++ {
		num := rr[i].Num().Int64()
		denom := rr[i].Denom().Int64()
		num2[i] = powcount(num, 2)
		num5[i] = powcount(num, 5)
		denom2[i] = powcount(denom, 2)
		denom5[i] = powcount(denom, 5)
		for j := 32 - (num2[i] - denom2[i]); j < 64; j++ {
			for k := 32 - (num5[i] - denom5[i]); k < 64; k++ {
				ans += int64(nd[j][k])
			}
		}
		nd[32+num2[i]-denom2[i]][32+num5[i]-denom5[i]]++
	}
	fmt.Fprintln(writer, ans)
}
func powcount(x, p int64) int {
	var ans int
	for x%p == 0 {
		ans++
		x /= p
	}
	return ans
}
func strtorat(s string) *big.Rat {
	ss := strings.Split(s, ".")
	var x, d int64
	d = 1
	for i := 0; i < len(ss[0]); i++ {
		x *= 10
		x += int64(ss[0][i] - '0')
	}
	if len(ss) == 2 {
		for i := 0; i < len(ss[1]); i++ {
			x *= 10
			d *= 10
			x += int64(ss[1][i] - '0')
		}
	}
	return big.NewRat(x, d)
}

func makeGrid(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 35088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
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++)
const int INF = 1<<28;

bool prime[123456*2+1] = {};

void era() {
	FOR(i, 2, 123456*2+1) {
		bool fst = true;
		for(int j=i; j<123456*2+1; j += i) {
			if(fst) {
				fst = false;
				continue;
			}
			prime[j] = true;
		}
	}
	return;
}

int main() {
	era();
	int n;
	while(cin >> n, n) {
		int cnt = 0;
		FOR(i, n+1, n*2+1)
			if(!prime[i]) cnt++;
		cout << cnt << endl;
	} 

	return 0;
}

Measured memory_bytes: 1400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var np = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            long c0 = a.Count(i => i % 2 == 0);
            long c1 = a.Count() - c0;
            long c0Pow = (long)Math.Pow(2, c0);
            long c1Odd = 0;
            long c1Even = 0;
            for (int i = 0; i <= c1; i++)
            {
                if (i % 2 == 0) c1Even += nCr(c1, i);
                else c1Odd += nCr(c1, i);
            }
            Console.WriteLine(np[1] == 0 ? c0Pow * c1Even : c0Pow * c1Odd);

        }
        static long nCr(long n, long r)
        {
            double x = 1;
            for (int i = 0; i < r; i++)
            {
                x *= n - i;
                x /= i + 1;
            }
            return (long)x;
        }
    }
}

Measured memory_bytes: 13396
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,M; cin >> N >> M;
	V<int> D(N); rep(i,N) cin >> D[i];
	VV<int> G(N);
	using P = pair<int,int>;
	map<P,int> mp;
	rep(i,M){
		int x,y; cin >> x >> y; x--,y--;
		G[x].pb(y);G[y].pb(x);
		mp[P(x,y)] = i;
		mp[P(y,x)] = i;
	}
	V<int> vs(N); rep(i,N) vs[i] = i;
	sort(all(vs),[&](int l,int r){return D[l]<D[r];});
	V<int> ans(M,1e9);
	string col(N,'?');
	rep(i,N){
		int v = vs[i];
		if(col[v] != '?') continue;
		for(int u: G[v]) if(col[u] != '?' || D[v] == D[u]){
			int eid = mp[P(v,u)];
			ans[eid] = D[v];
			if(col[u] == '?'){
				col[u] = 'B';
			}
			col[v] = col[u] ^ 'B' ^ 'W';
			break;
		}
		if(col[v] == '?'){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << col << endl;
	rep(i,M) cout << ans[i] << endl;
}


Measured memory_bytes: 35200
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 101
#define INF 1<<30

 int M[MAX][MAX],color[MAX],G[MAX],n,P[MAX];


int dijkstra(){
        int min,u,v,i;
        for(i=0;i<n;i++){
                     color[i]=WHITE;
                     G[i]=INF;
                     P[i]=0;
                     }

        G[0]=0;
        min=INF;

       while(1){
              min=INF;
              u=-1;
              for(i=0;i<n;i++){
                         if(color[i]!=BLACK && min>G[i]){
                                          min=G[i];
                                          u=i;
                                          }
                         }
              if(u==-1)break;
              color[u]=BLACK;
              for(v=0;v<n;v++){
                         if(color[v]!=BLACK && M[u][v]!=INF){
                                       if(G[v]>G[u]+M[u][v]){
                                                   G[v]=G[u]+M[u][v];
                                                   color[v]=GRAY;
                                                   }
                                       }
                          }
              }
      for(i=0;i<n;i++){
                   printf("%d %d\n",i,G[i]==INF?-1:G[i]);
                   }
      }
              


int main(){
        int i,j,v,c,u,k;
        scanf("%d",&n);
        for(i=0;i<n;i++){
                   for(j=0;j<n;j++){M[i][j]=INF;}
                   }
        
        for(i=0;i<n;i++){
                   scanf("%d%d",&u,&k);
                   for(j=0;j<k;j++){
                              scanf("%d%d",&v,&c);
                              M[u][v]=c;
                              }
                   }
        dijkstra();
        return 0;
        }


Measured memory_bytes: 1988
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  A,B,C,D = readline() |> split |> parseArray

  E=lcm(C,D)
  x=(B-(A-1))-((B÷C-(A-1)÷C)+(B÷D-(A-1)÷D)-(B÷E-(A-1)÷E))
  println(x)
end

main()


Measured memory_bytes: 168640
n = int(input())

s = 0
p = 0
for _ in range(n):
  t,x,y = map(int, input().split())
  s = t - s
  p = abs((x+y)-p)
  if s < p:
    print("No")
    exit()
  elif s%2 != p%2:
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 9136
# Nが100以下の時は全部れっきょ

import math
N, K = map(int, input().split())
mod = 10**9+7


def rev(X):
    return pow(X, mod-2, mod)


if N <= 100:
    dp = [[0 for i in range(N+2)] for i in range(K+1)]
    for i in range(1, N+1):
        dp[1][i] += 1
    for i in range(2, K+1):
        for j in range(1, N+1):
            dp[i][1] += dp[i-1][j]
            dp[i][N//j+1] -= dp[i-1][j]
        for j in range(1, N+2):
            dp[i][j] += dp[i][j-1]
    ans = 0
    for i in range(1, N+1):
        ans += dp[K][i]
    print(ans % mod)
    exit()


else:
    # N>100
    ans = 0
    L=0
    for i in range(10**5):
        if i**2>N:
            L=i  
            break
    B = N//L
    dp = [[0 for i in range(L+B)] for i in range(K+1)]
    cnt = [0 for i in range(L+B)]
    for i in range(1, B+1):
        dp[1][i] += 1
        cnt[i] = 1
    for i in range(B+1, B+L):
        x = B+L-i
        dp[1][i] += N//x-N//(x+1)
        cnt[i] = N//x-N//(x+1)
    for i in range(2, K+1):
        S = sum(dp[i-1])
        for j in range(1, L+B-1):
            dp[i][j] = S*cnt[j] % mod
            S -= dp[i-1][-j]
        dp[i][L+B-1] = S*cnt[L+B-1] % mod
    for i in range(1, L+B):
        ans += dp[K][i]
        ans %= mod
    print(ans)



Measured memory_bytes: 169792
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;

const int M=1e4+5;

char s[M];

char shift(char c,int n)
{
	int a=c-'A';
	a=(a+n)%26;
	return a+'A';
}

int main()
{
	int n; scanf("%d",&n);
	scanf("%s",s);
	int l=strlen(s);
	n%=26;
	for(int i=0;i<l;i++)
		s[i]=shift(s[i],n);
	printf("%s\n",s);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     int n,sum=0,d[100];
     cin>>n;
     for(int i=0;i<n;i++)
     {
         cin>>d[i];
     }
     for(int i=0;i<n;i++)
     {
         for(int j=i+1;j<n;j++)
         {
             sum=sum+d[i]*d[j];
         }
     }
     cout<<sum;
     return 0;
 }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

vector<string> an;
int main()
{
	int N, L;
	string S;
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> S;
		an.push_back(S);
	}
	sort(an.begin(), an.end());
	for (int i = 0; i < N; i++) cout << an[i];
	cout << endl;
}


Measured memory_bytes: 256
import sys
def q(a,h):
 d[a]=h
 for b in t[a]:q(b,h+1)
t,p,d={},{},{}
input()
for e in sys.stdin:
 e=e.split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
print('\n'.join(f"node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'}, [{', '.join(t[i])}]"for i in map(str,sorted(map(int,t)))))


Measured memory_bytes: 59988
N, X = list(map(int,input().split()))
L = list(map(int,input().split()))
prevd = 0
prevl = 0
ans = 0
for i in range(N+1):
    d = prevd + prevl
    if d <= X:
        ans += 1
    else:
        break
    if i != N:
        prevd = d
        prevl = L[i]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll A[200000];
const ll INF = 1e+15;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    ll sum = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
    }
    ll ans = INF;
    ll tmp = 0;
    for(int i = 0; i < N; i++){
        tmp += A[i];
        sum -= A[i];
        ans = min(ans, abs(sum-tmp));
    }
    cout << ans << endl;
}

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

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

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

	char c;
	long long cnt[5] = {0};
	for (int i = 0; i < N; i++) {
		scanf(" %c%*[^\n]", &c);
		// printf("%c\n", c);
		switch (c) {
			case 'M':
				cnt[0]++;
				break;
			case 'A':
				cnt[1]++;
				break;
			case 'R':
				cnt[2]++;
				break;
			case 'C':
				cnt[3]++;
				break;
			case 'H':
				cnt[4]++;
				break;
			default:
				break;
		}
	}

	long long result = 0;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				result += cnt[i] * cnt[j] * cnt[k];
				// printf("%d %d %d %lld \n", i, j, k, result);
			}
		}
	}
	printf("%lld", result);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) { //gcdを返す
	if(a == 0){
		return b;
	} else if (b == 0){
		return a;
	} else {
	  if(a < b) return gcd(b, a);
	  ll r;
	  while ((r=a%b)) {
	    a = b;
	    b = r;
	  }
	  return b;
	}
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
const ll mod = 1000000007;
int main(){
	ll N, L;
	cin >> N >> L;
	vl a(N);
	REP(i,N){
		cin >> a[i];
	}
	ll check;
	ll count = 0;
	REP(i, N-1){
		if(a[i] + a[i+1] >= L){
			check = i+1;
			count++;
		}
	}
	if(count == 0){
		cout << "Impossible" << endl;
	} else {
		cout << "Possible" << endl;
		for(ll i = 1; i < N; i++){
			if(i < check){
				cout << i << endl;
			}
		}
		for(ll j = N-1; j >= check; j--){
				cout << j << endl;
			}
	}
}

Measured memory_bytes: 1664
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := []rune(Scanner())
	if n[0] == n[1] && n[1] == n[2] {
		fmt.Println("Yes")
	} else if n[1] == n[2] && n[2] == n[3] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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 P(int n, int k){
        return fact[n] * ifact[n-k];
    }
};

int main(){
    ll n,m;
    cin >> n >> m;
    combination c(m+2);
    mint ans= 0;
    rep(i,n+1){
        mint memo = c(n,i) * c.P(m,i) * c.P(m-i,n-i) * c.P(m-i,n-i);
        if(i%2==0) ans += memo;
        else ans -= memo;
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 11068
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var N, T int
	fmt.Sscanf(scanner.Text(), "%d %d", &N, &T)

	cs := make([]int, N)
	ts := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &cs[i], &ts[i])
	}

	ans := math.MaxInt64
	for i := 0; i < N; i++ {
		if ts[i] <= T {
			ans = min(ans, cs[i])
		}
	}

	if ans == math.MaxInt64 {
		fmt.Println("TLE")
	} else {
		fmt.Println(ans)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  string s;
  cin >> s;

  if (s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }

  int c_cnt = 0, c_ind = 0;
  for (int i = 2; i < s.size() - 1; i++) {
    if (s[i] == 'C') {
      c_cnt++;
      c_ind = i;
    }
  }
  if (c_cnt != 1) {
    cout << "WA" << endl;
    return 0;
  }

  for (int i = 0; i < s.size(); i++) {
    if (i == 0 || i == c_ind) continue;
    if (isupper(s[i])) {
      cout << "WA" << endl;
      return 0;
    }
  }

  cout << "AC" << endl;
}


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

int cube[31];

void move(int k)
{
  switch (k)
  {
  case 0:
    // ???????????????
    swap(cube[7], cube[22]);
    swap(cube[8], cube[23]);
    swap(cube[9], cube[24]);
    swap(cube[13], cube[18]);
    swap(cube[10], cube[12]);
    break;
  case 1:
    // ?\\?????????
    swap(cube[1], cube[28]);
    swap(cube[2], cube[29]);
    swap(cube[3], cube[30]);
    swap(cube[15], cube[16]);
    swap(cube[19], cube[21]);
    break;
  case 2:
    // ????????????
    swap(cube[1], cube[24]);
    swap(cube[4], cube[27]);
    swap(cube[7], cube[30]);
    swap(cube[10], cube[21]);
    swap(cube[16], cube[18]);
    break;
  case 3:
    // ????????????
    swap(cube[3], cube[22]);
    swap(cube[6], cube[25]);
    swap(cube[9], cube[28]);
    swap(cube[12], cube[19]);
    swap(cube[13], cube[15]);
    break;
  default:
    break;
  }
}

bool complete()
{
  for (int i=1; i<=8; i++)
  {
    if (cube[1] != cube[1+i]) return false;
  }
  for (int i=1; i<=8; i++)
  {
    if (cube[22] != cube[22+i]) return false;
  }
  for (int i=1; i<=2; i++)
  {
    if (cube[10] != cube[10+i]) return false;
  }
  for (int i=1; i<=2; i++)
  {
    if (cube[13] != cube[13+i]) return false;
  }
  for (int i=1; i<=2; i++)
  {
    if (cube[16] != cube[16+i]) return false;
  }
  for (int i=1; i<=2; i++)
  {
    if (cube[19] != cube[19+i]) return false;
  }
  return true;
}

// ???????????¢?´¢?????????
// - cube????????£???????????°t?????????
// - ?????£??????????????´???????????¨?????????????????§??????????????°???t??????????????????
// - 8?????\?????????????????????????????¨??????1000?????????
int dfs(int t)
{
  if (complete()) return t;
  if (t >= 8) return 1000;

  int result = 1000;
  for (int i=0; i<4; i++)
  {
    move(i);
    result = min(result, dfs(t+1));
    move(i);
  }
  return result;
}

int main()
{
  int n;

  cin >> n;
  for (int i=0;i<n;i++)
  {
    for (int j=1;j<=30;j++)
    {
      cin >> cube[j];
    }
    cout << dfs(0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
H, W = map(int, input().split())
Map = [input() for _ in range(H)]
black_no1 = 0
A = [[0 for __ in range(W)] for _ in range(H)]
for i in range(H):
  for j in range(W):
    if Map[i][j] == '#':
      black_no1 += 1
      A[i][j] = 1
pos = [[0, 0]]
dfs = 1
clr = -1
while pos != []:
  dfs += 1
  n = len(pos)
  for i in range(n):
    p = pos[0]
    if p[0] > 0:
      if A[p[0]-1][p[1]] == 0:
        A[p[0]-1][p[1]] = 1
        pos.append([p[0]-1, p[1]])
      if p[0] - 1 == H - 1 and p[1] == W - 1:
        clr = 0
    if p[0] < H - 1:
      if A[p[0]+1][p[1]] == 0:
        A[p[0]+1][p[1]] = 1
        pos.append([p[0]+1, p[1]])
      if p[0] + 1 == H - 1 and p[1] == W - 1:
        clr = 0
    if p[1] > 0:
      if A[p[0]][p[1]-1] == 0:
        A[p[0]][p[1]-1] = 1
        pos.append([p[0], p[1]-1])
      if p[0] == H - 1 and p[1] - 1 == W - 1:
        clr = 0
    if p[1] < W - 1:
      if A[p[0]][p[1]+1] == 0:
        A[p[0]][p[1]+1] = 1
        pos.append([p[0], p[1]+1])
      if p[0] == H - 1 and p[1] + 1 == W - 1:
        clr = 0
    pos = pos[1:]
    if clr == 0:
      break
  if clr == 0:
    break
if clr == 0:
  print(H*W-dfs-black_no1)
else:
  print(clr)

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    int A, B, X;
    cin >> A >> B >> X;
    YES(A <= X && X <= A + B);
}


Measured memory_bytes: 256