akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static final int MOD = 1_000_000_007;

	public static void main(String[] args) {
		int N = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		long[] p10 = new long[N + 1];
		p10[0] = 1;
		for (int i = 0; i < N; ++i) {
			p10[i + 1] = p10[i] * 10 % MOD;
		}
		long[][] dp = new long[N + 1][1 << (X + Y + Z)];
		dp[0][1] = 1;
		long ans = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 1; j < (1 << (X + Y + Z)); ++j) {
				if (dp[i][j] == 0) continue;
				for (int k = 1; k <= 10; ++k) {
					if (k <= Z && (j & (1 << (X + Y + Z - k))) != 0) {
						ans += (dp[i][j] * p10[N - i - 1]) % MOD;
						continue;
					}
					int next = 1;
					for (int l = 0; k + l <= X; ++l) {
						if ((j & (1 << l)) == 0) continue;
						next |= 1 << (k + l);
					}
					for (int l = X; k + l <= X + Y; ++l) {
						if ((j & (1 << l)) == 0) continue;
						next |= 1 << (k + l);
					}
					for (int l = X + Y; k + l < X + Y + Z; ++l) {
						if ((j & (1 << l)) == 0) continue;
						next |= 1 << (k + l);
					}

					dp[i + 1][next] += dp[i][j];
					if (dp[i + 1][next] >= MOD) dp[i + 1][next] -= MOD;
				}
			}
		}
		System.out.println(ans % MOD);
	}
}


Measured memory_bytes: 57868
#include <cstdio>

int main()
{
  bool cards[4][13] = { false };
  int n;
  int d;
  char mark;
  
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf(" %c %d", &mark, &d);
    int m;
    switch (mark) {
      case 'S':
        m = 0;
        break;
      case 'H':
        m = 1;
        break;
      case 'C':
        m = 2;
        break;
      case 'D':
        m = 3;
        break;          
    }
    cards[m][d - 1] = true;
  }

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      if (cards[i][j] == false) {
        switch (i) {
          case 0:
            printf("S %d\n", j + 1);
            break;
          case 1:
            printf("H %d\n", j + 1);
            break;
          case 2:
            printf("C %d\n", j + 1);
            break;
          case 3:
            printf("D %d\n", j + 1);
            break;
        }
      }
    }
  }
}
  



Measured memory_bytes: 2732
#include<iostream>
#include<iomanip>
#include<math.h>

using namespace std;

bool get_snb( double , double , double , double , double& , double& );
double get_distance( double , double , double , double );

int main(void)
{
	double x1, x2, x3;
	double y1, y2, y3;

	double a[3] , b[3];

	double px, py;
	double r;

	int n;

	cin >> n;

	for( int k = 0 ; k < n ; k++ )
	{
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

		int i = 0;
		while(1)
		{
			if( get_snb( x1 , x2 , y1 , y2 , a[i] , b[i] ) == true ) i++;
			if( get_snb( x1 , x3 , y1 , y3 , a[i] , b[i] ) == true )
			{
				i++;
				if( i == 2 ) break;

			}
			if( get_snb( x2 , x3 , y2 , y3 , a[i] , b[i] ) == true )
			{
				i++;
				if( i == 2 ) break;
			}
		}

	
		px = -( b[0] - b[1] )/( a[0] - a[1] );
		py = a[0] * px + b[0];
	
		r = get_distance( x1 , px , y1 , py );

		cout.setf( ios::fixed , ios::floatfield );
		cout<< setprecision(3) << px << " " << py << " " << r << endl;
	}

	return 0;


}

bool get_snb( double x1 , double x2 , double y1 , double y2 , double& a , double& b )
{
	double cx, cy;
	a = -( x1 - x2 )/( y1 - y2 );

	if( y1 - y2 <= 0.0001 && y1 - y2 >= -0.0001 ) return false;
	if( x1 - x2 <= 0.0001 && x1 - x2 >= -0.0001 ) a = 0;
	
	cx = ( x1 + x2 ) / 2;
	cy = ( y1 + y2 ) / 2;

	b = cy - a * cx;

	return true;
}

double get_distance( double x1 , double x2 , double y1 , double y2 )
{
	return sqrt( (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) );
}

Measured memory_bytes: 1292
#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>

using namespace std;

void solve(int H, int W, vector<vector<string>> room) {
  vector<vector<int>> U(H);
  for (int i = 0; i < H; i++) {
    U[i].resize(W);
  }
  for (int j = 0; j < W; j++) {
    for (int i = 0; i < H; i++) {
      if (room[i][j] == "#") {
        U[i][j] = 0;
      } else if (i == 0) {
        U[i][j] = 1;
      } else {
        U[i][j] = U[i - 1][j] + 1;
      }
    }
  }

  vector<vector<int>> D(H);
  for (int i = 0; i < H; i++) {
    D[i].resize(W);
  }
  for (int j = 0; j < W; j++) {
    for (int i = H - 1; i >= 0; i--) {
      if (room[i][j] == "#") {
        D[i][j] = 0;
      } else if (i == H - 1) {
        D[i][j] = 1;
      } else {
        D[i][j] = D[i + 1][j] + 1;
      }
    }
  }

  vector<vector<int>> L(H);
  for (int i = 0; i < H; i++) {
    L[i].resize(W);
    for (int j = 0; j < W; j++) {
      if (room[i][j] == "#") {
        L[i][j] = 0;
      } else if (j == 0) {
        L[i][j] = 1;
      } else {
        L[i][j] = L[i][j - 1] + 1;
      }
    }
  }

  vector<vector<int>> R(H);
  for (int i = 0; i < H; i++) {
    R[i].resize(W);
    for (int j = W - 1; j >= 0; j--) {
      if (room[i][j] == "#") {
        R[i][j] = 0;
      } else if (j == W - 1) {
        R[i][j] = 1;
      } else {
        R[i][j] = R[i][j + 1] + 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3);
    }
  }
  printf("%d\n", ans);
}

int main() {
  int H, W;
  scanf("%d %d", &H, &W);
  vector<vector<string>> room(H);
  for (int i = 0; i < H; i++) {
    room[i].resize(W);
    string row;
    cin >> row;
    for (int j = 0; j < W; j++) {
      room[i][j] = row[j];
    }
  }
  solve(H, W, room);
  return 0;
}

Measured memory_bytes: 250752
#include <bits/stdc++.h>
 
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   int fn,sn; 
   vs ans={"YYMM", "MMYY", "AMBIGUOUS", "NA"};
   string s;
   cin>>s;
   fn=(s.at(0)-'0')*10+s.at(1)-'0';
   sn=(s.at(2)-'0')*10+s.at(3)-'0';
   if(1<=fn&&fn<=12){
       if(1<=sn&&sn<=12)cout<<ans.at(2)<<endl;
       else cout<<ans.at(1)<<endl;
   }else{
       if(1<=sn&&sn<=12)cout<<ans.at(0)<<endl;
       else cout<<ans.at(3)<<endl;
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int num[100009],pos[100009],ans[100009];
int main() {
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]=='R')
			for(int j=i+1;j<s.size()&&s[j]=='L';j++)
				num[j]=j-i,pos[j]=i;
		else
			for(int j=i-1;j>=0&&s[j]=='R';j--)
				num[j]=i-j,pos[j]=i;
	for(int i=0;i<s.size();i++)
		if(num[i]%2==0) ans[pos[i]]++;
		else if(s[i]=='R') ans[pos[i]-1]++;
			else ans[pos[i]+1]++;
	for(int i=0;i<s.size();i++) cout<<ans[i]<<' ';
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main() {
    int n, m;
    int count = 0;
    int ary[105];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &m);
        ary[i] = m;
        if (i % 2 == 0 && m % 2 == 1) count++;
    }
    printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi v(n); rep(i, n) cin >> v[i];
	vector<vi> dp(n + 1, vi(n + 1, -1));
	
	function<int(int,int)> rec = [&](int l, int r){
		//dbg(l, r);
		int &res = dp[l][r];
		if(res >= 0) return res;
		if(l >= r) return 1;
		for(int i = l + 2; i < r - 1; i++) if(rec(l, i) && rec(i, r)) return res = 1;
		if(l + 1 < r && v[l] == v[r - 1]){
			if(rec(l + 1, r - 1)) return res = 1;
			for(int i = l + 1; i < r - 1; i++) if(v[l] == v[i] && rec(l + 1, i) && rec(i + 1, r - 1)) return res = 1;
		}
		return res = 0;
	};
	cout << (rec(0, n) ? "yes" : "no") << endl;
	
	//rep(i, n+1) rep(j,n+1) cerr<<dp[i][j]<<(j==n?"\n":" ");
	
	return 0;
}


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

using namespace std;

typedef long long ll;

ll N, ans;

int main()
{
    cin >> N;
    for (ll i = N, j; i; i = j)
    {
        j = N / (N / i + 1);
        ll a = N / i, b = N % i;
        if (a == b) ans += i;
        else if (b == 0 && i != j + 1) ans += i - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main() {
    int N, M;
    int max = 0;
    
    cin >> N;
    vector<string> blue(N);
    for ( int i = 0 ; i < N ; i++ ) {
        cin >> blue.at(i);
    }
    
    cin >> M;
    vector<string> red(M);
    for ( int i = 0 ; i < M ; i++ ) {
        cin >> red.at(i);
    }
    
    for ( int i = 0 ; i < N ; i++ ) {
        int count = 0;
        string target = blue.at(i);
        
        for ( int l = 0 ; l < N ; l++ ) {
            if ( target == blue.at(l) ){
                count++;
            }
        }
        
        for ( int m = 0 ; m < M ; m++ ) {
            if ( target == red.at(m) ){
                count--;
            }
        }
        
        if ( max <= count ){
            max = count;
        }
    }
    cout << max << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<pair<int, int>>> edges(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges[a].emplace_back(b, c);
        edges[b].emplace_back(a, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    pq.push({0, k});
    vector<char> visited(n);
    vector<ll> lens(n, MLL);
    while(pq.size()){
        auto e = pq.top(); pq.pop();
        if(visited[e.second]){ continue; }
        visited[e.second] = true;
        lens[e.second] = e.first;
        for(auto edge : edges[e.second]){
            pq.push({e.first + edge.second, edge.first});
        }
    }
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << lens[x] + lens[y] << '\n';
    }
    return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> a(h);
  for(int i=0;i<h;i++){
    cin >> a.at(i);
  }
  vector<bool> row(h,false);
  vector<bool> col(w,false);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a.at(i).at(j) == '#'){
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }
  for(int i=0;i<h;i++){
    if(row.at(i)){
      for(int j=0;j<w;j++){
        if(col.at(j)){
          cout << a.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
inline char gc()
{
	static const int SIZE=1<<23;
	static char buf[SIZE],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SIZE,stdin),p1==p2)?EOF:*p1++;
}
//#define getchar gc
template<typename T>
inline T read(T &x)
{
	x=0;
	char ch;
	bool flag=false;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar())
		if(ch=='-') flag=true;
	while(ch>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	if(flag) x=-x;
	return x;
}
template<typename T>
inline void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
	return;
}
template<typename T>
inline void writeln(T x)
{
	write(x);
	putchar('\n');
	return;
}
const int N=200005;
int n;
int a[N];
bool isbig(int pos,int k)
{
	return a[pos]>k;
}
bool check(int k)
{
	for(int i=0;i<n-1;i++)
	{
		if(isbig(n+i,k)&&isbig(n+i+1,k)) return false;
		if(isbig(n-i,k)&&isbig(n-i-1,k)) return false;
		if(!isbig(n+i,k)&&!isbig(n+i+1,k)) return true;
		if(!isbig(n-i,k)&&!isbig(n-i-1,k)) return true;
	}
	return !isbig(1,k);
}
int main()
{
	read(n);
	for(int i=1;i<=2*n-1;i++)
		read(a[i]);
	int l=1,r=2*n-1,ans;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	write(ans);
	return 0; 
}

Measured memory_bytes: 1024
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int i,j,bi,n;cin>>n;
	vector<vector<llint>>a(n,vector<llint>(n));
	for(i=0;i<n;i++){for(j=0;j<n;j++){cin>>a[i][j];}}
	llint dp[65536]={0};
	for(bi=1;bi<(1<<n);bi++){
		int sb=0;
		for(i=0;i<n;i++){
			if(!(bi&(1<<i))){continue;}
			for(j=i+1;j<n;j++){
				if(!(bi&(1<<j))){continue;}
				dp[bi]+=a[i][j];
			}
		}
		while(sb<bi){
			if((~bi)&sb){sb+=(~bi)&sb;continue;}
			maxeq(dp[bi],dp[bi-sb]+dp[sb]);
			sb++;
		}
		
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;

typedef long long ll;

ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

int main(){
	ll a,b;
	cin>>a>>b;
	ll x=gcd(a,b);
	cout<<a*b/x<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    
    if (b > a*c)cout << c << endl;
    else cout << b/a << endl;
    
    return 0;
}



Measured memory_bytes: 256
class Modulo_Error(Exception):
    pass

class Modulo():
    def __init__(self,a,n):
        self.a=a%n
        self.n=n

    def __str__(self):
        return "{} (mod {})".format(self.a,self.n)

    #+,-
    def __pos__(self):
        return self

    def __neg__(self):
        return  Modulo(-self.a,self.n)

    #等号,不等号
    def __eq__(self,other):
        if isinstance(other,Modulo):
            return (self.a==other.a) and (self.n==other.n)
        elif isinstance(other,int):
            return (self-other).a==0

    def __neq__(self,other):
        return not(self==other)
    
    #加法
    def __add__(self,other):
        if isinstance(other,Modulo):
            if self.n!=other.n:
                raise Modulo_Error("異なる法同士の演算です.")
            return Modulo(self.a+other.a,self.n)
        elif isinstance(other,int):
            return Modulo(self.a+other,self.n)

    def __radd__(self,other):
        if isinstance(other,int):
            return Modulo(self.a+other,self.n)
        
    #減法
    def __sub__(self,other):
        return self+(-other)

    def __rsub__(self,other):
        if isinstance(other,int):
            return -self+other
        
    #乗法
    def __mul__(self,other):
        if isinstance(other,Modulo):
            if self.n!=other.n:
                raise Modulo_Error("異なる法同士の演算です.")
            return Modulo(self.a*other.a,self.n)
        elif isinstance(other,int):
            return Modulo(self.a*other,self.n)
        
    def __rmul__(self,other):
        if isinstance(other,int):
            return Modulo(self.a*other,self.n)
        
    #Modulo逆数
    def Modulo_Inverse(self):
        x0, y0, x1, y1 = 1, 0, 0, 1
        a,b=self.a,self.n
        while b != 0:
            q, a, b = a // b, b, a % b
            x0, x1 = x1, x0 - q * x1
            y0, y1 = y1, y0 - q * y1

        if a!=1:
            raise Modulo_Error("{}の逆数が存在しません".format(self))
        else:
            return Modulo(x0,self.n)
        
    #除法
    def __truediv__(self,other):
        return self*(other.Modulo_Inverse())
    
    def __rtruediv__(self,other):
        return other*(self.Modulo_Inverse())

    #累乗
    def __pow__(self,m):
        u=abs(m)

        r=Modulo(1,self.n)

        while u>0:
            if u%2==1:
                r*=self
            self*=self
            u=u>>1

        if m>=0:
            return r
        else:
            return r.Modulo_Inverse()

#階乗の剰余のリスト
def Factorial_Modulo_List(N,M,Inverse=False):
    X=[0]*(N+1)
    X[0]=Modulo(1,M)
    
    for i in range(1,N+1):
        X[i]=X[i-1]*i

    if Inverse:
        Y=[0]*(N+1)
        Y[-1]=1/X[-1]
        
        for j in range(N-1,-1,-1):
            Y[j]=Y[j+1]*(j+1)
        return X,Y
    else:
        return X
#---------------------------------------------------------------------
def nPr(n,r):
    return F[n]*G[n-r]

def nCr(n,r):
    return F[n]*G[n-r]*G[r]

A=10**9+7
N,M=map(int,input().split())
F,G=Factorial_Modulo_List(M,A,True)

Q=0
sgn=1
for k in range(N+1):
    Q+=sgn*nCr(N,k)*nPr(M,k)*nPr(M-k,N-k)**2
    sgn*=-1
print(Q.a)


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

int main() {
	int N;
	cin >> N;
	
	vector<int> d(N);
	for (int i = 0; i < N; ++i) {
		cin >> d.at(i);
	}
	
	set<int> num;
	for (int i = 0; i < N; ++i) {
		num.insert( d.at(i) );
	}
	
	cout << num.size() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main (){
    int n;cin>>n;
    vector<ll>V(3*n);
    for(int i=0;i<3*n;i++)cin>>V[i];
    sort(V.begin(),V.end());
    ll ret=0;
    for(int i=n;i<3*n;i+=2)ret+=V[i];
    cout<<ret<<endl;
    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <stdio.h>
#include <cassert>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	const int dx = tx - sx, dy = ty - sy;

	// Path 1
	for (int d = 0; d < dy; d++)cout << "U";
	for (int d = 0; d < dx; d++)cout << "R";


	// Path 2
	for (int d = 0; d < dy; d++)cout << "D";
	for (int d = 0; d < dx; d++)cout << "L";

	// Path 3
	cout << "L";
	for (int d = 0; d < dy+1; d++)cout << "U";
	for (int d = 0; d < dx+1; d++)cout << "R";
	cout << "D";

	// Path 4
	cout << "R";
	for (int d = 0; d < dy+1; d++)cout << "D";
	for (int d = 0; d < dx+1; d++)cout << "L";
	cout << "U";

	// EndLine
	cout << endl;
	return 0;
}

Measured memory_bytes: 3032
import math, string, fractions, heapq, re, array, bisect, sys, random, time, copy
import itertools as it
import collections as cl
import functools as ft


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n, m = LI()
result = {
    (1, 1): 1,
    (1, 2): 0, (2, 1): 0,
    (2, 2): 0
}

if (n, m) in result.keys():
    print(result[(n, m)])
elif n==1 or m==1:
    print(max(n, m)-2)
elif n==2 or m==2:
    print(0)
else:
    print((n-2)*(m-2))

Measured memory_bytes: 7620
import bisect
import sys
input=sys.stdin.readline
def main():
    N=int(input())
    S=input().rstrip()
    R,G,B=[],[],[]
    for i in range(N):
        if S[i]=='R':
            R.append(i)
        elif S[i]=='G':
            G.append(i)
        elif S[i]=='B':
            B.append(i)
    ans=0
    for i in range(N):
        for j in range(i):
            if(S[i]==S[j]):
                continue
            s=set([S[i],S[j]])
            if('B' not in s):
                lon=len(B)-bisect.bisect_left(B,i)
                mi=bisect.bisect_left(B,i+i-j)
                if(mi<len(B) and B[mi]==i*2-j):
                    lon-=1
            elif('R' not in s):
                lon=len(R)-bisect.bisect_left(R,i)
                mi=bisect.bisect_left(R,i+i-j)
                if(mi<len(R) and R[mi]==i*2-j):
                    lon-=1
            elif('G' not in s):
                lon=len(G)-bisect.bisect_left(G,i)
                mi=bisect.bisect_left(G,i+i-j)
                if(mi<len(G) and G[mi]==i*2-j):
                    lon-=1
            ans+=lon
        
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 75940
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

int main() {
    long long N, D, A;
    cin >> N >> D >> A;
    vector<pair<long long, long long>> v(N);
    rep(i, 0, N) { cin >> v[i].first >> v[i].second; }
    sort(v.begin(), v.end());
    long long tmp = 0;
    long long count = 0;
    queue<pair<long long, long long>> q;
    rep(i, 0, N) {
        while(q.size() > 0) {
            pair<long long, long long> p = q.front();
            if(p.second < v[i].first) {
                tmp -= p.first;
                q.pop();
                // cout << "pop" << endl;
            } else {
                break;
            }
        }
        // cout << "f" << v[i].first << ",s:" << v[i].second << "," << tmp <<
        // endl;
        if(v[i].second - tmp > 0) {
            // cout << "in" << endl;
            long long kai = (v[i].second - tmp + A - 1) / A;
            long long d = kai * A;
            q.push(make_pair(d, v[i].first + D + D));
            // cout << "qpush:" << d << "," << v[i].first + D + D << endl;
            tmp += d;
            count += kai;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(String[] args)
    {
        var l = Console.ReadLine().Split(' ')
            .Select(x => Int32.Parse(x)).ToArray();
        var n = l[0];
        var k = l[1];

        var f = new Boolean[n + 1].Select(x => false).ToArray();
        for (var i = 0; k > i; i++)
        {
            var d = Int32.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ')
                .Select(x => Int32.Parse(x)).ToArray();
            for (var j = 0; d > j; j++)
            {
                f[a[j]] = true;
            }
        }
        Console.WriteLine(f.Where(x => x == false).ToArray().Length - 1);
    }
}

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

const int N_MAX=100, M_MAX=100;
char p[N_MAX+1][M_MAX+1];

int main(){
	string s;
	cin >> s;
	int cnt=0;
	rep(i,3){
		if(s[i] == '1') cnt++;
	}
	cout << cnt << endl;
	return 0;
}




Measured memory_bytes: 256
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
/* Ordered Set Implementaton:

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    ll n = 0;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> m;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        m[a[i]]++;
    }
    ll suma = 0;
    for(auto x : m){
        suma = suma + ((x.second * (x.second - 1)) / 2LL);
    }
    for(int i = 0; i < n; i++){
        ll sub = m[a[i]];
        ll sumb = suma;
        sumb -= ((sub * (sub - 1)) / 2LL);
        sub--;
        sumb += ((sub * (sub - 1)) / 2LL);
        cout << sumb << "\n";
    }
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  vector<pair<long long int,int> > AB;
  for (int i=0;i<N;i++){
    pair<long long int,int> ab;
    cin >> ab.first >> ab.second;
    AB.push_back(ab);
  }
  sort(AB.begin(),AB.end());
  long long int ans=0;
  for(vector<pair<long long int,int> >::iterator e=AB.begin();M>0;e++){
    if (M>e->second){
      M-=e->second;
      ans += e->first*e->second;
    }else {
      ans += e->first*M;
      M=0;
    }
  }
  cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int x, k;
	cin>> x;

	k=1;
	while(1){
		if((k*x)%360==0){
			cout<< k <<endl;
			return 0;
		}
		k++;
	}
 
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

struct Event {
  int t;
  int x1,x2,y;
  bool operator<(const Event &b) const {
    return y < b.y;
  }
} event[200000];

int table[100005];
bool flag[2][100005];

int main() {
  int n,r;
  while(cin>>n>>r,n||r) {
    int W = 0;
    int H = 0;
    REP(i,n) {
      int x,y,p,q;
      cin>>x>>y>>p>>q;
      x++;y++;p++;q++;
      W = max(W,p);
      H = max(H,q);
      event[i*2]   = (Event){+1,x,p,y};
      event[i*2+1] = (Event){-1,x,p,q};
    }
    sort(event,event+2*n);
    memset(table,0,sizeof(table));
    int id = 0;
    int a = 0;
    int b = 0;
    bool *cur = flag[0];
    bool *pre = flag[1];
    for (int y=1; y<=H+1; ++y) {
      for (;id<2*n&&event[id].y==y;++id)
        for (int x=event[id].x1; x<event[id].x2; ++x)
          table[x] += event[id].t;
      for (int i=1; i<W; ++i) cur[i] = !!table[i];
      for (int i=1; i<=W; ++i) {
        a += cur[i];
        if (cur[i-1] ^ cur[i]) b++;
        if (pre[i] ^ cur[i]) b++;
      }
      swap(cur,pre);
    }
    cout << a << endl;
    if (r == 2) cout << b << endl;
  }
}

Measured memory_bytes: 1920
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int R, C;
int O[10][10000];

int calc(unsigned patt) {
  int res = 0;
  for (int i = 0; i < C; i++) {
    int cnt = 0;
    for (int j = 0; j < R; j++) {
      if (O[j][i] != ((patt & (1u << j)) != 0 ? true : false)) {
        ++cnt;
      }
    }
    res += max(cnt, R - cnt);
  }
  return res;
}

void solve() {
  int ans = 0;
  for (unsigned patt = 0; patt < (1u << R); patt++) {
    ans = max(ans, calc(patt));
  }
  printf("%d\n", ans);
}

int main() {
  for (;;) {
    scanf("%d%d", &R, &C);
    if (R == 0 && C == 0) {
      break;
    }

    for (int i = 0; i < R; i++) {
      for (int j = 0; j < C; j++) {
        int k = 0;
        scanf("%d", &k);
        O[i][j] = k == 1 ? true : false;
      }
    }
    solve();
  }

  return 0;
}

Measured memory_bytes: 1416
using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();
        int d = sc.NextInt();

        for (int i = 0; ; i++)
        {
            if (i % 2 == 0)
            {
                c -= b;
                if (c <= 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            else
            {
                a -= d;
                if (a <= 0)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

int main() {
    int n;
    cin >> n;
    int ans = 0, la_count = 0, fb_count = 0, ba_count = 0;
    for (int i = 0; i < n; i++) {
        string si;
        cin >> si;
        for (int j = 1; j < si.size(); j++) {
            if (si[j - 1] == 'A' && si[j] == 'B') {
                ans++;
            }
        }
        if (si[si.size() - 1] == 'A') {
            if (si[0] == 'B') {
                ba_count++;
            } else {
                la_count++;
            }
        } else {
            if (si[0] == 'B')
                fb_count++;
        }
    }

    if (ba_count > 0) {
        ans += ba_count - 1;
        if (fb_count > 0 || la_count > 0) {
            ans++;
        }
    }
    ans += min(fb_count, la_count);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{
    int i,n;
    scanf("%d",&n);
    if(1<=n && n<105){
        i=0;
    }else{
        if(105<=n && n<135){
        i=1;
    }else{
        if(135<=n && n<165){
        i=2;
    }else{
        if(165<=n && n<189){
        i=3;
    }else{
        if(189<=n && n<195){
        i=4;
    }else{ 
        i=5;
    };
    };
    };
    };
    };
    printf("%d",i);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    int min = INF;
    int ans = 0;
    rep(i,n) {
        if (p[i]<min) {
            ++ans;
            min = p[i];
        }
    }
    cout << ans << endl;
    return 0;
}

































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

int main() {
    string a,b;
    cin>>a>>b;
    int i,n=a.size();
    for(i=0;i<n;i++){
        if(a[i]!=b[n-1-i]){
            cout<<"NO";return 0;
        }
       
    }
    cout<<"YES";
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

const int N = 2e5 + 10;
const int MOD = 1e9 + 7;

int lst[N], f[N];

int main() {
	int n;
	memset(lst, 0, sizeof lst);
	scanf("%d", &n);
    f[0] = 0;
	for (int i = 1; i<= n; ++i) {
		int a;
		scanf("%d", &a);
		f[i] = f[i - 1];
		if (lst[a] != 0 && lst[a] != i - 1) f[i] =(f[i] + f[lst[a]] + 1) % MOD;
		lst[a] = i;
	}
	printf("%d\n", (f[n] + 1) % MOD);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(V) V.begin(), V.end()
#define PB push_back
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i,s.size()){
        ans+=s.at(i)-'0';
    }
    if(ans % 9 == 0){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 3716
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var a, b int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &a, &b)

	if a*b <= 0 {
		fmt.Println("Zero")
	} else if a > 0 {
		fmt.Println("Positive")
	} else {
		if (b-a)%2 == 0 {
			fmt.Println("Negative")
		} else {
			fmt.Println("Positive")
		}
	}
}


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

int a[1000000];

int main()
{
   
    int N , K;
    cin >> N >> K;
    
    for(int i = 0; i < N ; ++i)
    {
        cin >> a[i];
    }
    
    long long int sum = 0;
    sort(a, a+N);
    
    for(int i = 0 ; i < K; ++i)
    {
        sum += a[i];
    }
    
    cout << sum ;
    return 0;
}

Measured memory_bytes: 3140
from fractions import gcd


N = int(input())
lstA = list(map(int, input().split()))
lstL = [0] * N
lstR = [0] * N


for i in range(1, N):
    lstL[i] = gcd(lstL[i-1], lstA[i-1])
for i in range(N-1)[::-1]:
    lstR[i] = gcd(lstR[i+1], lstA[i+1])
lstGcd = [gcd(lstL[i], lstR[i]) for i in range(N)]
ans = max(lstGcd)


print(ans)


Measured memory_bytes: 16060
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;


void swap(char *a,char *b){
  char temp = *a;
  *a = *b;
  *b = temp;
}

int main(){
  int dx[] = {+1,-1,+4,-4};

  string start = "01234567";

  queue<string> que;
  map<string,int> d;
  que.push(start);
  d[start] = 0;

  while(que.size()){
    string q = que.front(); que.pop();
    int x = q.find("0");
    for(int i=0;i<4;i++){
      int next = x + dx[i];
      if( next>=0 && next<=7 && !(x==3&&next==4) && !(x==4&&next==3) ){
        string nextq = q;
        swap(&nextq[x],&nextq[next]);
        if(d.find(nextq)==d.end()){
          que.push(nextq);
          d[nextq] = d[q] + 1;
        }
      }
    }
  }

  while(1){
    string input = "";
    char temp;
    for(int i=0;i<8;i++){
      if(cin >> temp){
        input.push_back(temp);
      }else{
        return 0;
      }
    }
    cout << d[input] << endl;
  }

}

Measured memory_bytes: 3444
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        int max = 0;
        int min = 999999999;

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] < min) {
                min = a[i];
            }
            if (a[i] > max) {
                max = a[i];
            }
        }
        System.out.println(max - min);
    }

}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,l,x,sum = 0,tmp = 100000000;
    cin >> n >> l;
    vector<int>v(n);

    for(int i = 0;i < n;i++){
        v[i] = l+i+1-1;
        sum += v[i];
    }

    for(int i = 0;i < n;i++){
        if(tmp > abs(sum-(sum-v[i]))){
            tmp = abs(sum-(sum-v[i]));
            x = i;
        }
       
    }

    cout << sum - v[x] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

inline int tri(int a, int b, int c)
{
	if( (a<b+c) && (b<c+a) && (c<a+b) ) return 1;
	else return 0;
}

int main(void) {
	int n; cin >> n ;
	vector<int> l(n);
	rep(i,n) cin >> l[i];
	SORT(l);
	int ans=0;
	rep(i,n-2)rep(j,n-1){
		if(j<=i) continue;
		int a=l[i], b=l[j];
		int st = j+1;
		int ed = lower_bound(l.begin(),l.end(),a+b)-l.begin();
/* 		out(st);
		out(ed);
		out(ed-st); */
		if(ed-st<0) continue;
		ans += ed-st;
	}
	out(ans);
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] in1 = Console.ReadLine().Split(' ');
            string[] in2 = Console.ReadLine().Split(' ');

            List<int> vs = new List<int>();
            foreach (string s in in2)
            {
                vs.Add(int.Parse(s));
            }

            vs.Sort();
            int ans = 0;

            for (var i = 0; i < int.Parse(in1[1]); i++)
            {
                ans += vs[i];
            }
            Console.WriteLine("{0}", ans);
        }
            
    }
}


Measured memory_bytes: 28188
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n1 = input.nextInt();
        int n2 = input.nextInt();
        extracted(n1, n2);
        input.close();
    }

	private static void extracted(int n1, int n2) {
        int count = 0;
		for(int i=n1;i<=n2;i++){
            int m1 = i / 10000;
            int m2 = i % 10;
            int m3 = i % 10000 / 1000;
            int m4 = i % 100 / 10;
            if (m1 == m2 && m3 == m4)
                count++;
        }
        System.out.println(count);
	}
}

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

const int C = 26;
const int D = 365;

int d;
int c[C];
int s[D][C];

vector<int> t;

void read() {
  scanf("%d", &d);
  for (int i = 0; i < C; ++i) scanf("%d", &c[i]);
  for (int i = 0; i < d; ++i) {
    for (int j = 0; j < C; ++j) {
      scanf("%d", &s[i][j]);
    }
  }
}

int score[D];
int lst[D];
int eval(vector<int> t) {
  int cur = 0;
  for (int i = 0; i < D; ++i) lst[i] = -1;
  for (int i = 0; i < t.size(); ++i) {
    cur += s[i][t[i]];
    lst[t[i]] = i;
    for (int j = 0; j < C; ++j) {
      cur -= (i - lst[j]) * c[j];
    }

    score[i] = cur;
  }

  return cur;
}

vector<int> greedy() {
  vector<int> t;
  for (int i = 0; i < d; ++i) {
    t.push_back(0);
    for (int j = 1; j < C; ++j) {
      vector<int> nt = t;
      t.back() = j;
 
      if (eval(nt) > eval(t)) {
        t = nt;
      }
    }
  }
  return t;
}

void solve() {
  t = greedy();

  for (int k = 0; k < 16; ++k) {
    for (int i = 0; i < d; ++i) {
      for (int j = 0; j < C; ++j) {
        vector<int> nt = t;
        nt[i] = j;
        if (eval(nt) > eval(t)) t = nt;
      }
    }
  }
}

void print() {
  for (int i = 0; i < d; ++i) printf("%d\n", t[i] + 1);
}

void printScore() {
  eval(t);
  for (int i = 0; i < d; ++i) printf("%d\n", score[i]);
}

int main() {
  read();
  solve();
  print();
  // cerr << eval(t) << endl;
  // printScore();
  return 0;
}


Measured memory_bytes: 3932
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
template<typename T> void remove(std::vector<T>& vector, unsigned int index){vector.erase(vector.begin() + index);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int k,x;
    cin >> k >> x;
    for(int i = x - k + 1; i <= x + k -1;++i)
    {
        cout << i << " ";
    }
    cout << endl;
}


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

using namespace std;

int main(){
    string S,T;
    cin>>S>>T;
    int s,t;
    for(s=0,t=0;s<S.size();s+=2){
        while(t<T.size()&&T[t]!=S[s])t++;
        if(t>=T.size()) break;
        t++;
    }
    if(s>=S.size()){
        cout<<"Yes"<<endl;
        return 0;
    }
    for(s=1,t=0;s<S.size();s+=2){
        while(t<T.size()&&T[t]!=S[s])t++;
        if(t>=T.size()) break;
        t++;
    }
    if(s>=S.size()){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3208
def main():
    N = int(input())
    S = input()
    
    ans = S.count('R') * S.count('G') * S.count('B')

    for i in range(N-2):
        for j in range(i+1, i+1+(N-1-i)//2):
            k = j + (j - i)
            if S[i] != S[j] != S[k] != S[i]:
                ans -= 1
            
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 73592