akhauriyash/Code-Regression huggingface dataset:
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
string to_string (string s) { return "\"" + s + "\""; }
template<typename T> string to_string (vector<T>);
template<typename U, typename V> string to_string (pair<U, V> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T> string to_string (vector<T> v) {
	string res = "["; for (int i = 0; i < (int)v.size() - 1; i++) res += to_string(v[i]) + ", ";
	if (!v.empty()) res += to_string(v.back());	res += "]"; return res; }

const int K = 18;
const int N = (1 << K) + 100;
ll fl[N], fr[N], gl[N], gr[N], a[N], n;
ll h[N][K], rd[N]; /* rd[x] = k => x rounded down to nearest power of 2 = 2^k */

ll mx (int i, int j) {
	int k = rd[j - i + 1];
	return max(h[i][k], h[j - (1 << k) + 1][k]);
}

/* return first index at which value is > val in [ix...n] */
ll calcFR (int ix, ll val) {
	int l = ix, r = n + 1, mid;
	while (l < r) {
		mid = (l + r) >> 1;
		if (mx(ix, mid) > val) r = mid;
		else l = mid + 1;
	}
	return r;
}

/* returns first index (going from right to left) at which value is > val in [1...ix] */
ll calcFL (int ix, ll val) {
	int l = 0, r = ix, mid;
	while (l < r) {
		mid = (l + r) - ((l + r) >> 1);
		if (mx(mid, ix) > val) l = mid;
		else r = mid - 1;
	}
	return l;
}

void prep() {
	rd[1] = 0; /* 2 ^ 0 */
	for (int k = 1; k < K; k++)
		for (int i = (1 << k); i <= (1 << (k + 1)) - 1; i++)
			rd[i] = k;
	
	for (int i = 1; i <= n; i++) h[i][0] = a[i];
	for (int k = 1; (1 << k) <= n; k++)
		for (int i = 1; i <= n - (1 << k) + 1; i++)
			h[i][k] = max(h[i][k - 1], h[i + (1 << (k - 1))][k - 1]);
	
	fl[0] = fr[n + 1] = 0;

	for (int i = n; i >= 1; i--) {
		fr[i] = calcFR(i, a[i]);
		gr[i] = calcFR(fr[i] + 1, a[i]);

		fr[i] = fr[i] - i;
		gr[i] = gr[i] - i - fr[i];
	}

	for (int i = 1; i <= n; i++) {
		fl[i] = calcFL(i, a[i]);
		gl[i] = calcFL(fl[i] - 1, a[i]);

		fl[i] = i - fl[i];
		gl[i] = i - gl[i] - fl[i];
	}
}

ll solve() {
	ll ans = 0;
	for (int i = 1; i <= n; i++) ans += a[i] * (fr[i] * gl[i] + fl[i] * gr[i]);
	return ans;
}

int main () { 
#ifdef XVENOM
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
#endif

	scanf("%lld", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	prep();
	printf("%lld\n", solve());
}

Measured memory_bytes: 26880
#define _USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll T;
ld A, B, H, M, H_theta, H_X, H_Y, M_theta, M_X, M_Y, D;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	T = 1;
	
	for (ll q = 0; q < T; q++) {
		
		cin >> A >> B >> H >> M;
		
		H_theta = 2.0 * M_PI * (H * 60.0 + M) / 720.0;
		H_X = A * cos(H_theta);
		H_Y = A * sin(H_theta);
		
		M_theta = 2.0 * M_PI * M / 60.0;
		M_X = B * cos(M_theta);
		M_Y = B * sin(M_theta);
		
		D = sqrt((H_X - M_X) * (H_X - M_X) + (H_Y - M_Y) * (H_Y - M_Y));
		
		cout << fixed << setprecision(14) << D << "\n";
		
	}
		
    return 0;
}

Measured memory_bytes: 4188
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VL x(n), y(n);
    REP(i,n){
        x[i] = in();
        y[i] = in();
    }

    ll ans = n;
    REP(i,n) FOR(j,i+1,n-1){
        ll p = x[j] - x[i];
        ll q = y[j] - y[i];
        ll tmp = n;
        REP(a,n) REP(b,n){
            if (x[a] - x[b] == p && y[a] - y[b] == q) tmp--;
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
  int n, l;
  cin >> n >> l;
  int sum = 0;
  int a[n + 1];
  if (l >= 0)
  {
    for (int i = 2; i <= n; i++)
    {
      sum += l + i - 1;
    }
  }
  else if (l < 0)
  {
    if (abs(l) >= n)
    {
      for (int i = 1; i < n; i++)
      {
        sum += l + i - 1;
      }
    }
    else
    {
      for (int i = 1; i <= n; i++)
      {
        sum += l + i - 1;
      }
    }
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
map<char,ll> mp;
char l[5]={'M','A','R','C','H'};

int main(){
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++){
        string s;
        cin>>s;
        char a=s[0];
        mp[a]++;
    }
    ll ans=0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                ans+=mp[l[i]]*mp[l[j]]*mp[l[k]];
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():

    s,t = map(str, input().split())

    a,b = map(int, input().split())

    u = str(input())

    if u == s:
        print(str(a-1), str(b))
    elif u == t:
        print(str(a), str(b-1))

if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
def count_of_divide_2(n):
    ret = 0
    while n % 2 == 0:
        n /= 2
        ret += 1
    return ret


n = int(input())
ans = 1
for i in range(1, n+1):
    if count_of_divide_2(ans) < count_of_divide_2(i):
        ans = i

print(ans)

Measured memory_bytes: 2940
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <cassert>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=(a%10/5)+(a%5), a/=10; return res;}

int main() {
  int x; cin>>x;
  x-=400; x/=200; cout<<8-x<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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 ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll a,b,c,k;
    IN(a,b,c,k);
    ll ans = 0;
    if(a+b>=k) ans = min(a,k);
    else ans = a - (k-a-b);
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
using namespace std;
typedef long long ll;

ll fact (int n) {
    if (n == 1) {
        return 1;
    }
    return fact(n-1) * n % 1000000007;
}

int main(void){
    int n, m;
    cin >> n >> m;
    if (max(n, m) - min(n, m) >= 2) {
        cout << 0 << endl;
    }
    else if (n == m) {
        cout << (2 * fact(n) * fact(m)) % 1000000007 << endl;
    }
    else {
        cout << (fact(max(n, m)) * fact(min(n, m))) % 1000000007 << endl;
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll d(ll x)
{
    int sum = 0;
    while (x)
        sum++, x /= 10;
    return sum;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll sol = n;
    for (ll i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
            sol = min(sol, max(d(i), d(n / i)));
    }
    cout << sol;
}


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

string s, t;

int main()
{
	ios::sync_with_stdio(false);
	cin >> s >> t;
	t.erase(t.size() - 1, t.size());
	if (t == s) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

#define int long long int
#define pb push_back
#define MAX 100005
#define mod (int)(1e18+7)
#define sp fixed<<setprecision(12)
/*
vector<int> primes;
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    
}

int power(int a,int n,int p){
    int res=1;
    while(n){
        if(n&1){
            res=(res*a)%p;
            n--;
        }else{
            a=(a*a)%p;
            n/=2;
        }
    }
    return res;
}
*/

void minWindow(string &s, string &t) {
        int n=s.length();
        int m=t.length();
        if(m>n){
            cout<<"No String\n";
            return;
        }
        int hash_s[256]={0};
        int hash_t[256]={0};
        for(int i=0;i<m;i++){
            hash_t[t[i]]++;
        }
        int start=0,start_indx=-1,min_len=INT_MAX;
        int count=0;
        for(int last=0;last<n;last++){
            hash_s[s[last]]++;
            if(hash_t[s[last]]!=0 and hash_s[s[last]]<=hash_t[s[last]]){
                count++;
            }
            if(count==m){
                while( (hash_s[s[start]] > hash_t[s[start]]) or (hash_t[s[start]]==0) ){
                    if((hash_t[s[start]]!=0) and hash_s[s[start]] > hash_t[s[start]]){
                        hash_s[s[start]]--;
                    }
                    start++;
                }
                int curr_len=last-start+1;
                if(curr_len < min_len){
                    min_len=curr_len;
                    start_indx=start;
                }
            }
        }
        if(start_indx==-1){
            cout<<"No String\n";
            return;
        }
        cout<<s.substr(start_indx,min_len)<<"\n";
}

int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;

    int t=1;
    //cin>>t;
    //int it=1;
    while(t--){
        int l,r,n;
        cin>>n;
        int a;
        int ct=0;
        for(int i=1;i<=n;i++){
            cin>>a;
            if(a&1 and i&1){
                ct++;
            }
        }
        cout<<ct<<"\n";
    }

    return 0;
    
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
signed main(){
  long long n,w,worth,value,dp[5][100005],ans=0;
  cin>>n>>w;

  for(int i=0;i<=w;i++){
    dp[0][i]=0;
  }

  for(int i=1;i<=n;i++){
    cin>>worth>>value;
    for(int j=0;j<=w;j++){
      dp[i%3][j]=0;
    }
    for(int j=1;j<worth;j++){
      dp[i%3][j]=dp[(i-1)%3][j];
    }
    for(int j=worth;j<=w;j++){
      dp[i%3][j]=max(dp[(i-1)%3][j-worth]+value,dp[(i-1)%3][j]);
    }
  }
  
  for(int i=0;i<=w;i++){
    ans=max(dp[n%3][i],ans);
  }
  cout<<ans<<endl;
  return(0);
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x;
string s;



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	vll A(n+1);
	for(ll i=1;i<=n;i++) cin>>A[i];

	ll XOR = 0,sum = A[1] + A[2];
	for(ll i=3;i<=n;i++) XOR^=A[i];

	ll val = sum - XOR;
	
	if(val & 1 || sum < XOR) {
		cout<<-1;
		return;
	}

	ll AND = val/2;
	ll a =0,b=0;

	for(ll i=0;i<=39;i++) {
		ll x = (1ll << i);
        ll xx = XOR & x;
        ll yy = AND & x;
        
        if(xx == x && yy == x) {
        	cout<<-1;
        	return;
        }
        else if(xx == 0) {
        	a += yy;
        	b += yy;
        }
        else {
        	b += x;
        }
	}

	for (ll i = 39; i >= 0; i--){
        ll x = (1ll << i);
        if(((b&x) == x) && ((a&x) == 0)){
            if(b-x >= A[2]) b -= x, a += x;
        }
    }		

    if(a && b >= A[2])
    	cout<<A[1] - a;
    else cout<<-1;newl;
}


int main() {
	fastio; randomINT;
	//cin >> T;
	while(T--) {		
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
//const ll INFL = 1LL << 60;//10^18 = 2^60
const ll INFL = 1LL << 60;
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll N;
ll a[510][510];
void solve(ll l, ll r, ll level){
  if(l == r) return;
  ll m = (l + r) / 2;
  for(ll i = l; i <= m; i++){
    for(ll j = m+1; j <= r; j++){
      a[i][j] = level;
    }
  }
  solve(l, m, level + 1);
  solve(m+1, r, level + 1);
}


int main(){
  cin >> N;
  solve(1, N, 1);
  for(ll i = 1; i <= N-1; i++){
    for(ll j = i + 1; j <= N; j++){
      cout << a[i][j];
      if(j == N) cout << endl;
      else cout << " ";
    }
  }
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int  N,M;
    int cnt=0;
    int temp;
    int total=0;
    cin>>N>>M;
    vector<int> A(N,0);
    for(int i=0;i<N;i++)
    {
        cin>>temp;
        A[i]=temp;
        total+=temp;

    }
    for(int i=0;i<N;i++)
    {
        if((double)A[i]>=(double)1/(double)(4*M)*(double)total)
            cnt++;
    }

    if(cnt>=M)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args)throws Throwable {
        MyScanner sc=new MyScanner();
        PrintWriter pw=new PrintWriter(System.out);

        int n=sc.nextInt();
        int [] a=new int [n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt()-(i+1);
        }
        Arrays.sort(a);
        int b=a[n/2];
        long ans=0;
        for(int i=0;i<n;i++)
            ans+=Math.abs(a[i]-b);
        pw.println(ans);
        pw.flush();
        pw.close();
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {while (st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch (IOException e) {e.printStackTrace();}}
            return st.nextToken();}
        int nextInt() {return Integer.parseInt(next());}
        long nextLong() {return Long.parseLong(next());}
        double nextDouble() {return Double.parseDouble(next());}
        String nextLine(){String str = "";
            try {str = br.readLine();}
            catch (IOException e) {e.printStackTrace();}
            return str;}
    }
}

Measured memory_bytes: 48340
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = 1000000010;
const int MAX = 300000;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> h(N + 1);
    int dp[100010];
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
        dp[i] = INF;
    }
    dp[1] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= K; j++) {
            if (i + j <= N) {
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=(a)&&(a)<b)
using namespace std;
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
int w,h,f[21][21],ans,sx,sy;
void rec(int n,int x,int y){
	if(n>=ans)return;
	rep(i,4){
		int mx=x+dx[i],my=y+dy[i];
		if(!ck(mx,w)||!ck(my,h)||f[my][mx]==1)continue;
		for(;;){
			if(f[my][mx]==3){
				ans=n; return;
			}
			mx+=dx[i],my+=dy[i];
			if(!ck(mx,w)||!ck(my,h))break;
			if(f[my][mx]==1){
				f[my][mx]=0; rec(n+1,mx-dx[i],my-dy[i]);
				f[my][mx]=1; break;
			}
		}
	}
}
int main() {
	while(cin>>w>>h,w){
		rep(y,h)rep(x,w){
			cin>>f[y][x];
			if(f[y][x]==2)sx=x,sy=y;
		}
		ans=11; rec(1,sx,sy);
		cout<<(ans>10?-1:ans)<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static boolean[][] list;
	static boolean[] k;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)return false;
		
		list = new boolean[n+1][n+1];
		k = new boolean[n+1];
		for(boolean[] a : list)Arrays.fill(a, false);
		Arrays.fill(k, false);
		for(int i = 1; i < list.length; i++){
			int c = sc.nextInt();
			for(int j = 1; j <= c; j++){
				list[i][sc.nextInt()] = true;
			}
		}
		int c = sc.nextInt();
		for(int i = 1; i <= c; i++){
			k[sc.nextInt()] = true;
		}
		return true;
	}
	
	static void solve(){
		boolean isIdentify = true;
		boolean isHeCriminal = true;
		int criminal = -1;
		for(int i = 1; i < list.length; i++){
			for(int j = 1; j < list[0].length; j++){
				if(k[j] && !list[i][j])isHeCriminal = false;
			}
			if(criminal == -1 && isHeCriminal){
				criminal = i;
			}else if(isHeCriminal){
				isIdentify = false;
			}
			isHeCriminal = true;
		}
		if(isIdentify){
			System.out.println(criminal);
		}else{
			System.out.println(-1);
		}
		
	}

}

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

using namespace std;

int u[100001];

 main () {
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	int n, m;
	cin >> n >> m;
	for (int i = 1;i <= m;i ++) {
		int a, b;
		cin >> a >> b;
		u[a] ++;
		u[b] ++;
	}
	for (int i = 1;i <= n;i ++) {
		if (u[i] % 2) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

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

    if(a==b && a!=c) cout << "Yes" << endl;
    else if(a==c && a!=b) cout << "Yes" << endl;
    else if(b==c && a!=b) cout << "Yes" << endl;
    else cout<< "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main()
{
	int N;
	unsigned long long int sum = 0;
	cin >> N;
	int *A = new int[N];
	int *B = new int[N - 1];
	for (int i = 0; i < N-1; i++) {
		cin >> B[i];
	}
	A[0] = B[0];
	A[N - 1] = B[N - 2];
	for (int i = 1; i < N - 1; i++) {
		A[i] = min(B[i - 1], B[i]);
	}
	for (int i = 0; i < N; i++) {
		sum += A[i];
	}
	cout << sum << endl;
	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    rep(i, n-1) {
        if (a[i] == a[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}



Measured memory_bytes: 1024
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    vector<int> a(3 * N);
    read(a);

    sort(all(a));

    int l = 0;
    int r = 3 * N - 1;
    i64 ans = 0;
    rep(i, 0, N) {
        ans += a[r - 1];
        ++l;
        --r;
        --r;
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    int n;
    string s;
    cin>>n>>s;
    vector<int> b(n,0),w(n,0);
    rep(i,n){
        if(s[i]=='#') b[i]=1;
        else w[i]=1;
    }
    vector<int> sb(n+1,0),sw(n+1,0);
    rep(i,n){
        sb[i+1]=sb[i]+b[i];
        sw[i+1]=sw[i]+w[i];
    }

    bool ok=true;
    rep(i,n){
        if(s[i]=='.') ok=false;
    }

    if(ok){
        cout<<0<<endl;
        return 0;
    }

    int ans=n;
    rep(i,n+1){
        ans=min(ans,sb[i]+sw[n]-sw[i]);
    }

    cout<<ans<<endl;
}


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

int main(){
    int n, num[100] = {};
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> num[i]; 
    }
    for(int i=n-1; i>=1; i--){
        cout << num[i] << " ";
    }
    cout << num[0] << endl;

    return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>

main(){
  int a,b;
  int i,temp;


  while(1){
    if(scanf("%d %d", &a, &b)==EOF) break;

    if(a>=b){
      for(i=1;i<=b;i++){
	if(a%i==0 && b%i==0) temp=i;
      }
      printf("%d\n", temp);
    }
    else{
      for(i=1;i<=a;i++){
	if(a%i==0 && b%i==0) temp=i;
      }
      printf("%d\n", temp);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
ll d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int f(ll a){
  for(int i=2;i<=sqrt(a);i++)if(a%i<1)return 0;
  return 1;
}
int main(void){
  int a,ans=0;
  FOR(4){
    scanf("%d",&a);
    ans+=a;
  }
  PRL(ans);
}



Measured memory_bytes: 2096
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int D, G, P[10], C[10];

int main() {
    cin >> D >> G;
    REP(i, D) cin >> P[i] >> C[i];

    int ans = 100000000;
    REP(i, 1 << D) {
        int rest_i = D - 1, count = 0, score = 0;
        REP(j, D) {
            if ((i >> j) & 1) {
                count += P[j];
                score += (j + 1) * 100 * P[j] + C[j];
            }
            else {
                rest_i = j;
            }
        }

        int s = (rest_i + 1) * 100;
        if (G - score > s * (P[rest_i] - 1)) continue;
        if (score < G) count += (G - score + s - 1) / s;
        ans = min(ans, count);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
char ch[20];
map<string, int>m;
map<string, int>::iterator it;
int main(void)
{
	long long n, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ch;
		sort(ch,ch+10);
		ch[10] = '\0';
		if (!m.count(ch))
		{
			m[ch] = 0;
		}
		m[ch] += 1;
	}
	for (it = m.begin(); it != m.end(); it++)
	{
		int k=it->second;
		for (int i = 0; i < k; i++)
		{
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 11136
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<class Val>
struct BinaryIndexedTree {
    int n;
    vector<Val> t;
    BinaryIndexedTree() {}
    BinaryIndexedTree(int _n) :n(_n + 1), t(_n + 1) {}
    void add(int k, Val val) {
        k++;
        while (k < n) {
            t[k] += val;
            k += (k&-k);
        }
    }
    void set(int k, Val val) {
        add(k, -sum(k, k + 1));
        add(k, val);
    }
    Val sum(int k) {
        Val r = 0;
        while (k > 0) {
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    Val sum(int l, int r) {
        return sum(r) - sum(l);
    }
};

template<class Val>
vector<Val> compress(vector<Val> &v) {
    vector<Val> a = v;
    sort(all(a));
    a.erase(unique(all(a)), a.end());
    each(b, v)b = (int)(lower_bound(all(a), b) - a.begin());
    return a;
}

void solve() {
    int Q;
    cin >> Q;
    vi P(Q), A(Q), B(Q);

    rep(i, Q) {
        cin >> P[i];
        if (P[i] == 1) {
            cin >> A[i] >> B[i];
        }
    }

    auto C = compress(A);
    int N = sz(C);
    BinaryIndexedTree<ll> sumA(N), cntA(N);

    set<int> S;
    ll sb = 0;
    int x = A[0], m = 0;
    rep(i, Q) {
        if (P[i] == 1) {
            m++;
            sumA.add(A[i], C[A[i]]);
            cntA.add(A[i], 1);
            S.insert(A[i]);
            sb += B[i];
            auto it = S.find(x);
            auto itit = it;
            if (cntA.sum(*it) >= (m + 1) / 2) {
                --it;
            } else if (cntA.sum(*it + 1) < (m + 1) / 2) {
                ++it;
            }
            x = *it;
        } else {
            ll ans = sb;
            ans += cntA.sum(x)*C[x] - sumA.sum(x);
            ans += sumA.sum(x, N) - cntA.sum(x, N)*C[x];
            cout << C[x] << ' ' << ans << endl;
        }
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 12032
N = int(input())
lst = [0] + [int(x) for x in input().split()] + [0]
total = 0
for i in range(N + 1):
    total += abs(lst[i] - lst[i + 1])

for i in range(1, N + 1):
    a = abs(lst[i - 1] - lst[i])
    b = abs(lst[i] - lst[i + 1])
    c = abs(lst[i - 1] - lst[i + 1])
    print(total - a - b + c)

Measured memory_bytes: 14048
from collections import Counter

n=int(input())

def soinsu(n):
    S = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            S.append(i)
    if S == []:
        S.append(n)
    else:
        if n != 1:
            S.append(n)
    return S
L=[]
if n >= 2:
    for i in range(2, n + 1):
        L = L + soinsu(i)
LC = Counter(L)

C2 = 0
C4 = 0
C14 = 0
C24 = 0
C74 = 0

for v in LC.values():
    if v >= 2:
        C2 += 1
        if v >= 4:
            C4 += 1
            if v >= 14:
                C14 += 1
                if v >= 24:
                    C24 += 1
                    if v >= 74:
                        C74 += 1

r = C4 * (C4 - 1) // 2 * (C2 - 2) + C14 * (C4 - 1) + C24 * (C2 - 1) + C74

print(r)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
  char a[3];

    cin >> a[0] >> a[1] >> a[2];
    for(int i=0; i<3; i++)
      if(a[i]=='9') cout << 1;
      else cout << 9;
    cout << endl;
}


Measured memory_bytes: 256
/**
 *   author: malviyanshiv
 *   created: 09 January 2019  23:27:27
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define MAX 100005

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

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

void optimizeIO(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}


int main(){
	optimizeIO();

    int n, m;
    cin >> n >> m;
    vector< vector<char> > maze(n, vector<char>(m));
    vector< vector<int> > dp(n, vector<int>(m));

    REP(i, 0, n)
        REP(j, 0, m)
            cin >> maze[i][j];

    bool flag = true;
    REP(i, 0, n){
        if( maze[i][0] == '#')
            flag = false;
        if( flag )
            dp[i][0] = 1;
        else
            dp[i][0] = 0;
    }
    flag = true;
    REP(j, 0, m){
        if( maze[0][j] == '#')
            flag = false;
        if( flag )
            dp[0][j] = 1;
        else
            dp[0][j] = 0;
    }

    REP(i, 1, n){
        REP(j, 1, m){
            if( maze[i][j] == '#' )
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
        }
    }

    cout << dp[n-1][m-1]%MOD << endl;

	return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include <cstring>
#include<bits/stdc++.h> 
using namespace std;   
long long n,m;  
int main()  
{  
    cin>>n>>m;  
    if (n==1 and m==1) cout<<1<<endl;  
    else if (n==1) cout<<m-2<<endl;  
    else if (m==1) cout<<n-2<<endl;  
    else cout<<(n-2)*(m-2)<<endl;  
    return 0;  
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
char s[3][N];
int l[3];
bool vis[9][N];
void work(bool vis[],char a[],char b[]){
	for(int i=0;a[i];i++)
		for(int j=0;a[i+j]&&b[j];j++)
			if(a[i+j]!='?'&&b[j]!='?'&&a[i+j]!=b[j]){vis[i]=1;break;}
}
bool check(int i,int j,int a,int b){
	if(a>b)swap(i,j),swap(a,b);
	b-=a;
	return b>=l[i]||!vis[i*3+j][b];
}
bool judge(int j,int k){
	return check(0,1,0,j)&&check(0,2,0,k)&&check(1,2,j,k);
}
int main(){
	scanf("%s%s%s",s[0],s[1],s[2]);
	for(int i=0;i<3;i++)l[i]=strlen(s[i]);
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			if(i!=j)work(vis[i*3+j],s[i],s[j]);
	int ans=N*10;
	for(int i=-l[2]-l[1];i<=l[0]+l[2];i++)
		for(int j=-l[2]-l[1];j<=l[0]+l[1];j++)
			if(judge(i,j))ans=min(ans,max(l[0],max(l[1]+i,l[2]+j))-min(0,min(i,j)));
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
const int MAX = 101010;
vector<int> member[MAX];
set<int> graph[MAX];
int memo[MAX];

// https://ja.wikipedia.org/wiki/幅優先探索
// ※bfsの動作確認用.
// @param m: 参加者.
// @param l: 連結成分番号.
// @param: 特に無し.
void bfs(int m, int l){
    
    // 1. 終了条件設定.
    if(memo[m] >= 1) return;
    
    // 2. 空のキュー.
    queue<int> q;
    
    // 3. 参加者 m をキュー q に追加.
    memo[m] = l;
    q.push(m);
    while(!q.empty()){
        
        // 4. キューから取り出す.
        int u = q.front();
        q.pop();
        
        // 5. 取り出した要素を処理.
        for(auto &e : graph[u]){
             // 6. 訪問済であれば, 処理をスキップ.
            if(memo[e] > 0)            continue;
            if(memo[e] == 0 && e != m) memo[e] = l, q.push(e);
        }
    }
    return;
}

int main(){
    
    // 1. 入力情報.
    int N, M;
    scanf("%d %d", &N, &M);
    
    // 2. 言語ごとに, 参加者情報を保存.
    rep(i, N){
        int K, L;
        scanf("%d", &K);
        rep(j, K) scanf("%d", &L), L--, member[L].pb(i);
    }
    rep(i, M){
        for(auto &p : member[i]){
            int f = member[i].front();
            if(f != p) graph[f].insert(p), graph[p].insert(f);
        }
    }
    
    // 4. 連結成分の個数をカウント.
    int ans = 1;
    rep(i, N) if(memo[i] == 0) bfs(i, ans), ans++;
    
    // 5. 出力.
    printf("%s\n", (ans == 2) ? "YES" : "NO");
    return 0;
    
}

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


#include <bits/stdc++.h>

#define MOD 1e9+7

using namespace std;

class CSnukeFestival {
public:
    static void solve(std::istream &cin, std::ostream &cout) {
        int n;
        cin >> n;
        vector<int64_t> a_vec(n);
        vector<int64_t> b_vec(n);
        vector<int64_t> c_vec(n);
        for (int i = 0; i < n; ++i) cin >> a_vec[i];
        for (int i = 0; i < n; ++i) cin >> b_vec[i];
        for (int i = 0; i < n; ++i) cin >> c_vec[i];
        sort(a_vec.begin(), a_vec.end());
        sort(b_vec.begin(), b_vec.end());
        sort(c_vec.begin(), c_vec.end());
        int64_t ans = 0;
        for (int i = 0; i < n; ++i) {
            int64_t b = b_vec[i];
            auto a = lower_bound(a_vec.begin(), a_vec.end(), b) - a_vec.begin();
            auto c = upper_bound(c_vec.begin(), c_vec.end(), b) - c_vec.begin();
            ans += a * (n - c);
        }
        cout << ans << endl;
    }
};


int main() {
    CSnukeFestival solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[101];
	int l,i,j,s=0;
	cin>>a;
	l=strlen(a);
	for(i=l-1,j=0;i>=l/2&&i>=j;i--,j++){
		if(int(a[i])!=int(a[j])) s++;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1){
		c-=b;
		if(c<=0){
			printf("Yes\n");
			break;
		}
		a-=d;
		if(a<=0){
			printf("No\n");
			break;
		}
	}
}

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

int main() {
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  
  for(int i=0; i<n; i++){
    cin >> a.at(i);
  }
  
  int b = 0;
  int answer = 0;
  for(int i=1; i<n; i++){
    if(a.at(b) == 2){
      answer = i;
      break;
    }
    b = a.at(b) - 1;
  }
  
  if(answer == 0){
    cout << -1 << endl;
  }
  else{
    cout << answer << endl;
  }
  
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(void) {
  int S;
  int h, m, s;
  cin >> S;
  h = S / 3600;
  S = S % 3600;
  m = S / 60;
  S = S % 60;
  s = S;
  cout << h << ':' << m << ':' << s << endl;
  return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
using std::swap;


int main() {
	float N, D;
	cin >> N >> D;
	cout << ceil(N / (2 * D + 1))<< "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */


int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    cout << a[0] * a[1] / 2 << endl;
}



Measured memory_bytes: 256