akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll N=200001;
const ll INF=1e18*7;
ll n;
vector<ll> a,wa;
int main(){
	cin>>n;
	a.resize(n);
	wa.resize(n);
	FOR(i,0,n)cin>>a[i];
	FOR(i,0,n)a[i]-=(i+1);
	SORT(a);
	wa[0]=a[0];
	FOR(i,1,n)wa[i] = wa[i-1] + a[i];
	ll ans = INF;
	ans = min(ans,abs( wa[0] - (1)*a[0] )+abs(wa[n-1] - wa[0] - a[0]*(n-1)));
	FOR(i,0,n){
		ans = min(ans,abs( wa[i] - (i+1)*a[i] )+abs(wa[n-1] - wa[i] - a[i]*(n-i-1)));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll r,c,k;
    cin>>r>>c;
    char grid[r][c],ans[r][c];
    for(ll i=0;i<r;i++){
        for(ll j=0;j<c;j++){
            cin>>grid[i][j];
            ans[i][j]=grid[i][j];
        }
    }
    for(ll i=0;i<r;i++){
        k=0;
        for(ll j=0;j<c;j++){
            if(grid[i][j]=='.')k++;
        }
        if(k==c){
            for(ll j=0;j<c;j++)ans[i][j]='o';
        }
    }
    for(ll i=0;i<c;i++){
        k=0;
        for(ll j=0;j<r;j++){
            if(grid[j][i]=='.')k++;
        }
        if(k==r){
            for(ll j=0;j<r;j++)ans[j][i]='o';
        }
    }
    for(ll i=0;i<r;i++){
        k=0;
        for(ll j=0;j<c;j++){
            if(ans[i][j]!='o')cout<<ans[i][j];
            else k++;
        }
        if(k!=c)cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  string s;
  cin >> s;

  if (s[0] == s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int iMAX = 1000000;
const int iMAX_half = 500000;
int isPrime[iMAX];

int main()
{
	int n, cnt, sqSize;
	bool prime[iMAX_half];

	cnt = 1;
	sqSize = 1000;
	prime[0] = prime[1] = 0; prime[2] = 1;
	for(int i=3; i < iMAX; i+=2) prime[(i-1)>>1] = 1;
	for(int i=3; i < sqSize; i+=2) {
		if(prime[(i-1)>>1]) {
			for(int j=i+i+i; j < iMAX; j+=(i*2))
				if(j & 1) prime[(j-1)>>1] = 0;
		}
	}
	isPrime[0] = isPrime[1] = 0; isPrime[2] = 1;
	for(int i=3; i < iMAX; i+=2) {
		if(prime[(i-1)>>1]) cnt++;
		isPrime[(i-1)>>1] = cnt;
	}
	while(cin >> n)
	{
		if(n == 2)
			cout << 1 << endl;
		else
			cout << isPrime[(n-1)>>1] << endl;
	}

	return 0;
}

Measured memory_bytes: 0
//ক্ষ্যাপা মানুষ চিনলে না
//রহিনু দিনে বন বাদাড়ে
//রাত পোহালে ঘর  খাঁচায়
//ও ক্ষ্যাপা মানুষ চিনলে না

#include<bits/stdc++.h>

using namespace std;

#define in(x)               cin>>x;
#define iin(x,y)            cin>>x>>y;
#define iiin(x,y,z)         cin>>x>>y>>z;
#define cous(x)             cout<<x<<' ';
#define coul(x)             cout<<x<<endl;
#define Taken               int t;cin>>t;while(t--)
#define Start               int main()
#define fastio              ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define vein                vector<int>
#define vell                vector<long long int>
#define pb(x)               push_back(x)
#define mapii               map<int,int>
#define pairii              pair<int,int>
#define inf                 1e9
#define mset(a,b)           memset(a,b,sizeof(a));
#define ifor(p,d,t)         for(int i = p ; i != d ; i += t)
#define jfor(p,d,t)         for(int j = p ; j != d ; j += t)
#define kfor(p,d,t)         for(int k = p ; k != d ; k += t)

typedef long long ll;



Start{

    fastio

    int n;
    
    in(n)
    
    int a[n];
    
    ifor(0,n,1)
    {
        in(a[i])
    }
    
    
    sort(a,a+n);
    
    ll ans = 0;
    
    ifor( 0,n,1 )
    {
        jfor( i+1,n,1 )
        {
            kfor( j+1,n,1 )
            {
                if(a[k] < a[i] + a[j] && (a[i]!=a[j] && a[j]!=a[k])) ans++;
            }
        }
    }
    
    coul(ans)
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

// https://img.atcoder.jp/m-solutions2020/editorial.pdf
void solve() {
    int n, k;
    cin >> n >> k;
    vector<double> a(n);
    cin >> a;
    rep(i, n) a[i] = log(a[i]);
    // cerr << a << endl;
    
    double now = 0;
    rep(i, k) now += a[i];
    rep3(i, k, n) {
        if (now < now - a[i - k] + a[i]) {
            cout << "Yes" << endl;
        } else cout << "No" << endl;
    }
}



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

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

  vector<int> vec(100, 0);
  rep(i, n) vec[d[i] - 1] = 1;

  int ans = 0;
  rep(i, 100) {
    if (vec[i] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
cnt=0
a=A[0]
b=0

for i in range(n-1):
  if A[i]<=A[i+1]:
    a=A[i+1]
  else:
    cnt+=a-b
    a=A[i+1]
    b=A[i+1]
if a>b:
  cnt+=a-b
print(cnt)

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

#include<algorithm>

int main(){

	int n, m, a[101];
	int i;

	cin >> n >> m;
	for (i = 1; i <= n; i++)
		cin >> a[i];

	for (int k = 1; k <= m; k++){
		i = 1;
		while (i != n){
			if (a[i] % k > a[i + 1] % k) swap(a[i], a[i + 1]);
			i++;
		}
	}

	for (i = 1; i <= n; i++)
		cout << a[i] << endl;
}

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  int a[100][100];
  cin >> N;
  REP(i, N) REP(j, N) cin >> a[i][j];
  int sum[101][101] = {};
  REP(i, N) REP(j, N) sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + a[i][j];
  int ans = -10000;
  REP(i, N) FOR(j, i, N) REP(k, N) FOR(l, k, N){
    ans = max(ans, sum[j + 1][l + 1] - sum[i][l + 1] - sum[j + 1][k] + sum[i][k]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;

int main(){
    int n;
    cin >> n;
    using P = pair<int, int>;
    vector<P> r(n), b(n);
    rep(i, n) cin >> r[i].first >> r[i].second;
    rep(i, n) cin >> b[i].first >> b[i].second;

    sort(all(r));
    sort(all(b));

    vector<bool> used(n);
    int ans = 0;
    rep(i, n){
        int idx = -1;
        int maxv = -1;
        rep(j, n){
            if(!used[j] && r[j].first < b[i].first && r[j].second < b[i].second && maxv < r[j].second){
                idx = j;
                maxv = r[j].second;
            }
        }
        if(idx != -1){
            ans++;
            used[idx] = true;
        }
    }

    cout << ans << endl;
}

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


int n,k;
int x[100000];

int main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n>>k;
		for(int i=0;i<n;i++)cin>>x[i];
		for(int i=0;i<n-1;i++)
			x[i]=x[i+1]-x[i];
		sort(x,x+n-1);
		if(k>=n){
			cout<<0<<endl;
		}else{
			int s=0;
			for(int i=0;i<n-k;i++){
				s+=x[i];
			}
			cout<<s<<endl;
		}
	}
	return 0;
}

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

using namespace std;

int main(void) {
  string keyword;
  string str;
  int cnt = 0;
  cin >> keyword;

  while (cin >> str) {
    if (str == "END_OF_TEXT")
      break;
    for (int i = 0; i < keyword.size(); i++) {
      if (keyword[i] >= 'A' && keyword[i] <= 'Z')
        keyword[i] = tolower(keyword[i]);
    }

    for (int i = 0; i < str.size(); i++) {
      if (str[i] >= 'A' && str[i] <= 'Z')
        str[i] = tolower(str[i]);
    }

    if(str == keyword)
      cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 3144
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  string input;
  int n,k;
  cin >> n >> input >> k;
  char target = input[k-1];
  
  for(int i = 0; i < n; i++){
    if(input[i] == target){
      cout << input[i];
    } else {
      cout << '*';
    }
  }
  cout << endl;
  

  return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> D(K);
    for (int i = 0; i < K; i++) cin >> D[i];
    int ans = N;
    while(true) {
        int M = ans;
        bool check = true;
        while (M > 0) {
            int t = M % 10;
            for (int d : D) {
                if (t == d) {
                    check = false;
                    break;
                }
            }
            if (!check) break;
            M /= 10;
        }
        if (check) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define MAX 12
#define mk make_pair
#define INF 1<<28
string s[20];
bool vis[20][20];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int n,w,h,d[MAX][MAX],c;
int dp[1<<MAX][MAX];
int rec(int s,int v){
  if(dp[s][v]>=0)return dp[s][v];
  if(s==(1<<n)-1&&v!=0){return dp[s][v]=0;}
  int res=INF;
  for(int u=0;u<n;u++) 
    if(!(s>>u&1))
      res=min(res,rec(s|1<<u,u)+d[v][u]);
  return dp[s][v]=res;
}
void bfs(int x2,int y2,int k){
  r(i,20)r(j,20)vis[i][j]=0;
  queue<pair<pair<int,int>,int> > q;
  vis[x2][y2]=1;
  q.push(mk(mk(x2,y2),0));
  while(!q.empty()){
    pair<pair<int,int>,int>p=q.front();q.pop();
    int p1=p.first.first,p2=p.first.second,p3=p.second;//cout<<p1<<p2<<p3<<endl;
    r(i,4){
      int x=dx[i]+p1;
      int y=dy[i]+p2;
      if(x>=0&&x<w&&y>=0&&y<h)
        if(!vis[x][y]&&(s[y][x]!='x')){
          if(0<=s[y][x]&&s[y][x]<12)
            d[k][(int)s[y][x]]=p3+1,q.push(mk(mk(x,y),p3+1));
          else if(k!=0&&s[y][x]=='o')
            d[k][0]=p3+1,q.push(mk(mk(x,y),p3+1));
          else q.push(mk(mk(x,y),p3+1));
          vis[x][y]=1;
        }
    }
  }
}
int main(){
  while(cin>>w>>h,w){c=1;
    int a,b;
    vector<pair<int,int> >v;
    r(i,h)cin>>s[i];
    r(j,w)r(i,h)if(s[i][j]=='*')s[i][j]=c++,v.push_back(make_pair(j,i));
  memset(dp,-1,sizeof(dp));
  n=c;
  r(i,MAX)r(j,MAX)d[i][j]=INF;
  r(j,w)r(i,h)if(s[i][j]=='o')a=j,b=i;
  bfs(a,b,0);
  r(i,c-1)bfs(v[i].first,v[i].second,i+1);
  //r(i,c){r(j,c){cout<<d[i][j]<<' ';}cout<<endl;}cout<<d[0][1];
  int p=rec(1,0);
  if(p==INF)p=-1;
  cout<<p<<endl;
  }
}

Measured memory_bytes: 3352
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};

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

int npr[100000];
vector<int> pr;

ll m,a,b;

void solve(){
  pair<ll,PI> ans(0,mp(0,0));
  rep(i,SZ(pr)){
    if(pr[i]*2>m) break;
    rep(j,i+1){
      if(pr[i]*pr[j]>m) break;
      if(pr[j]*b<a*pr[i]) continue;
      ans=max(ans,mp((ll)pr[i]*pr[j],mp(pr[i],pr[j])));
    }
  }

  cout << ans.S.S << ' ' << ans.S.F << endl;
}

int main(int argc, char *argv[])
{
  npr[0]=npr[1]=true;
  for(int i=2;i<100000;++i){
    if(npr[i]) continue;
    pr.pb(i);
    for(int j=i*2;j<100000;j+=i) npr[j]=true;
  }
  while(cin >> m >> a >> b,m) solve();
  return 0;
}

Measured memory_bytes: 1716
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
typedef long long ll;


int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int pre = -999;
  for(int i = 0; i < n; ++i) {
    if(pre <= a[i]-1) {
      pre = a[i]-1;
    } else if(pre <= a[i]) {
      pre = a[i];
    } else {
      puts("No");
      return 0;
    }
  }
  puts("Yes");

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
struct dice{
  int x[6];
  void roll_x(){roll(0,4,5,1);}
  void roll_y(){roll(0,2,5,3);}
  void roll_z(){roll(1,3,4,2);}
 
  vector<dice> all_rolls(){
    vector<dice> res;
    for(int k=0; k<6; (k&1 ? roll_y() : roll_x()), k++){
      for(int i=0; i<4; roll_z(),i++){
        res.push_back(*this);
      }
    }
    return res;
  }
 
  void roll(int a,int b,int c,int d){
    int tmp = x[a];
    x[a] = x[b];
    x[b] = x[c];
    x[c] = x[d];
    x[d] = tmp;
  }
};
 
vector<dice> a[4];
int n,ans;
 
void solve(vector<int> z) {
  if(z.size()==n) {
    int sum=0;
    dice v[n];
    for(int i=0; i<n; i++) v[i]=a[i][z[i]];
    for(int i=0; i<6; i++) {
      int c[30];
      memset(c,0,sizeof(c));
      for(int j=0; j<n; j++) c[v[j].x[i]]++;
      int ma=0;
      for(int i=0; i<30; i++) ma=max(ma,c[i]);
      sum+=n-ma;
    }
    ans=min(ans,sum);
    return;
  }
  for(int i=0; i<a[z.size()].size(); i++) {
    vector<int> y=z;
    y.push_back(i);
    solve(y);
  }
}
 
int main() {
  while(cin >> n && n) {
    for(int i=0; i<n; i++) a[i].clear();
    ans=1000000007;
 
    map<string, int> m;m.clear();
    for(int i=0; i<n; i++) {
      dice b;
      for(int j=0; j<6; j++) {
    string s;
    cin >> s;
    if(!m[s]) {
      int q=m.size()+1;
      m[s]=q;
    }
    b.x[j]=m[s];
      }
      a[i]=b.all_rolls();
    }
    vector<int> y;
    solve(y);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1248
#include<iostream>
#include<algorithm>
using namespace std;
long long xl[100000];
int main()
{
	int n,ans;
	cin>>n;
	ans=n;
	for(int i=0;i<n;i++)
	{
		cin>>xl[i];
	}
	sort(xl,xl+n);
	for(int i=1;i<n;i++)
	{
		if(xl[i-1]==xl[i])
		{
			ans-=2;
			xl[i-1]=xl[i]=-1;
		}
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 1024
N, limit = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(N)]
ans = 2000
for i in range(N):
    if arr[i][1] <= limit:
        ans = min(ans, arr[i][0])
if ans == 2000:
    print('TLE')
else:
    print(ans)

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

typedef long long ll;
const int N = 100010;

int n, v[N], W, w[N];
int f[110][N];

int main() {
	scanf("%d%d", &n, &W);
	int sum = 0;
	for(int i = 1; i <= n; ++i) scanf("%d%d", &w[i], &v[i]), sum += v[i];
	memset(f, 0x3f, sizeof(f));
	f[0][0] = 0;
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		for(int j = 0; j <= sum; ++j) {
			if(j >= v[i]) f[i][j] = min(f[i][j], f[i - 1][j - v[i]] + w[i]);
			f[i][j] = min(f[i][j], f[i - 1][j]);
			if(f[i][j] <= W) ans = max(ans, j);
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 43264
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b;
  cin>>a>>b;
  int N,M;
  cin>>N>>M;
string h;
  cin>>h;
  if(a==h) N=N-1;
  if(b==h) M=M-1;
  cout<<N<<' '<<M;
}


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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  ll n, k;
  cin >> n >> k;

  vecll s(n+1);
  s[0]=0;
  rep(i,n){
    s[i+1]=s[i]+(i+1);
  }

  //prtall(s);

  ll ans=0;
  REP(i,k,n+2){
    //prt3(s[n], s[(n-i>0 ? n-i : 0)], s[i-1]);
    ans+=s[n]-s[(n-i>0 ? n-i : 0)]-s[i-1]+1;
    ans%=MOD;
  }

  prt(ans);

}


Measured memory_bytes: 4840
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

bool bl[101];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a,b,c,d; cin >> a >> b >> c >> d;
    REP(i,101) bl[i] = 1;
    for(int i=0; i<a; i++) bl[i] = 0;
    for(int i=b; i<101; i++) bl[i] = 0;
    for(int i=0; i<c; i++) bl[i] = 0;
    for(int i=d; i<101; i++) bl[i] = 0;
    int ans = 0;
    REP(i,101) if(bl[i]) ans++;
    out(ans);

    return 0;
}

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

#define ll  long long
#define pb push_back
#define mp make_pair
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;


int main() {
    
    int t, n, m;
    cin>>n;
    int a[n+1][3];
    int dp[n+1][3];
    memset(dp,0,sizeof(dp));
    Fo(i,n){
        cin>>a[i][0]>>a[i][1]>>a[i][2];


    }
   
    fo(i,3) dp[0][i]=0;
    for(int i=1;i<=n;i++){
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);

    }
    int ma=INT_MIN;
    
    fo(i,3){
    
        ma=max(ma,dp[n][i]);
    }
    cout<<ma<<endl;

    return 0;
}




Measured memory_bytes: 2560
R,C,K = map(int,input().split())
V = [[0 for c in range(C+1)] for r in range(R+1)]
for i in range(K):
	r,c,v = map(int,input().split())
	V[r][c] = v

dp = [[0 for i in range(4)] for j in range(C+1)]
for r in range(1, R+1):
	for c in range(1, C+1):
		v = V[r][c]
		under_val = max(dp[c])
		dp[c][0] = max(under_val, dp[c-1][0])
		if v > 0:
			dp[c][1] = max(under_val + v, dp[c-1][0] + v, dp[c-1][1])
			dp[c][2] = max(dp[c-1][1] + v, dp[c-1][2])
			dp[c][3] = max(dp[c-1][2] + v, dp[c-1][3])
		else:
			dp[c][1] = dp[c-1][1]
			dp[c][2] = dp[c-1][2]
			dp[c][3] = dp[c-1][3]
print(max(dp[-1]))

Measured memory_bytes: 149860
/*
ID: tohoast1
TASK: transform
LANG: C++
*/
#include <bits/stdc++.h>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speedup ios_base::sync_with_stdio(NULL)
#define fin freopen("transform.in", "r", stdin)
#define fout freopen("transform.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
LL a, b;

int main() {
    speedup;
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    cin.tie(0); cout.tie(0);
    cin >> a >> b;
    cout << (a * b) / __gcd(a, b);
    ///time;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[20];
int cur;
long long num(){
	long long ret=0;
	while('0'<=str[cur]&&str[cur]<='9'){
	//	printf("%d\n",cur);
		ret*=10;
		ret+=str[cur]-'0';
		cur++;
	}
	return ret;
}
long long mul(){
	long long ret=num();
	while(str[cur]=='*'){
		cur++;
		ret*=num();
	}
	return ret;
}
long long plus(){
	long long ret=mul();
	while(str[cur]=='+'){
		cur++;
		ret+=mul();
	}
	return ret;
}
int main(){
	scanf("%s",str);
	long long a;scanf("%lld",&a);
	long long M=plus();
	long long L=0;
	cur=0;
	long long tmp=0;
	int last=0;
	while(str[cur]){
		tmp=0;
		while('0'<=str[cur]&&str[cur]<='9'){
			tmp*=10;
			tmp+=str[cur]-'0';
			cur++;
		}//printf("%lld\n",L);
		
		if(last)L*=tmp;
		else L+=tmp;
		if(!str[cur])break;
		if(str[cur]=='*')last=1;
		else last=0;
		cur++;
	}
	if(a==M&&a==L)printf("U\n");
	if(a==M&&a!=L)printf("M\n");
	if(a!=M&&a!=L)printf("I\n");
	if(a!=M&&a==L)printf("L\n");
}

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

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

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)
int l;
int r;
vector<pii> v;

int main(){
  cin >> l;
  r = log2(l);
  int n = r+1;
  int m = 2*r;
  l -= pow(2,r);
  int node = n-1;
  int len = pow(2,r);
  while(l > 0 && node > 0){
    //cout << node <<endl;
    if(l>=pow(2,node-1)){
      v.push_back(pii(node,len));
      m++;
      l -= pow(2,node-1);
      len += pow(2,node-1);
    }
    node--;
  }
  cout << n << " " << m <<endl;
  REP(i,n-1){
    cout << i+1 << " " << i+2 << " " << pow(2,i) << endl;
    cout << i+1 << " " << i+2 << " " << 0 << endl;
  }
  for(int i = 0; i < v.size();i++){
    cout << v[i].first << " " << n << " " << v[i].second << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector <long> a(n);
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int tmp = 0;
    //bool flag = true;
    int cnt = 0;
    for(int i = 0 ; i < n ; i++){
        if(tmp == a[i]){
            cnt--;
            tmp = 0;
        }else{
            cnt++;
            tmp = a[i];
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
#define Maxn 200010
int A[Maxn];

struct S{
    int at,val;
}st[Maxn<<1];
int top;

inline void rd(int &x){
    x=0;char ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
}

inline bool Judge(int mid){
    top=0;
    st[++top]=(S){1,1};
    for(register int i=2;i<=n;++i)
        if(A[i]>A[i-1])st[++top]=(S){A[i-1]+1,1};
        else{
            while(top&&st[top].at>A[i])top--;
            int pre=top;
            while(top&&st[top].val==mid)top--;
            if(!top)return false;
            int last;
            int haha=st[top].val;
            if(pre!=top)last=st[top+1].at-1;
            else last=A[i];
            if(st[top].at!=last){
                st[++top]=(S){last,haha+1};
                if(last<A[i])st[++top]=(S){last+1,1};
            }else{
                top--;
                st[++top]=(S){last,haha+1};
                if(last<A[i])st[++top]=(S){last+1,1};
            }
        }
    return true;
}

int main(){
    rd(n);
    for(register int i=1;i<=n;++i)rd(A[i]);
    int l=1,r=n;
    while(l<r){
        int mid=(l+r)>>1;
        if(Judge(mid))r=mid;
        else l=mid+1;
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 2560
def waru(a,b):
  if a%b==0:
    return a//b
  else:
    return (a//b)+1
N,K=map(int,input().split())
L=list(map(int,input().split()))
mina=min(L)
ind=list()
R=[0]*N
for i in range(N):
  if L[i]==mina:
    ind.append(i)
    R[i]+=1
for i in range(1,N):
  R[i]=R[i-1]+R[i]
s=ind[0]
a=waru(s,K-1)
b=(a*(K-1))-s
susumi=b+s+1
#.......a. b+sだけ進んでる
while True:
  if susumi>=N:
    print(a)
    break
  if R[min(susumi+K,N-1)]-R[susumi]>0:
    susumi+=K
    a+=1
  else:
    susumi+=K-1
    a+=1

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

int main()
{
    int N, mx = 100, sum = 0;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int p;
        cin >> p;
        sum += p;
        if (p > mx) mx = p;
    }
    cout << sum - mx / 2 << '\n';
    return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (true)
    {
        if ((C -= B) <= 0)
        {
            cout << "Yes" << endl;
            break;
        }
        else if ((A -= D) <= 0)
        {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}


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

int main(){
	int k, s, c=0;
	cin >> k >> s;

	for(int x=0; x<=k; x++){
		for(int y=0; y<=k; y++){
			int z = s-x-y;
			if(z>=0&&z<=k) c++;
		}
	}
	cout << c << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func check(a, b []string) bool {
	la := len(a)
	lb := len(b)
	for i := 0; i <= la - lb; i++ {
		for j := 0; j <= la-lb; j++ {
			flg := true
			for k := 0; k < lb; k++ {
				if a[i+k][j:j+lb] != b[k] {
					flg = false
					break
				}
			}
			if flg {
				return true
			}
		}
	}
	return false
}

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	a := make([]string, N)
	b := make([]string, M)
	for i := range a {
		fmt.Scan(&a[i])
	}
	for i := range b {
		fmt.Scan(&b[i])
	}
	if check(a, b) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int max_eq = 0;
  max_eq = max(a*b, max(a+b, a-b));
  
  cout << max_eq << endl;
}
  

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

class dice{

public:
  int _1,_2,_3,_4,_5,_6,temp;

  void moveN(){
    temp=_1;
    _1=_2;
    _2=_6;
    _6=_5;
    _5=temp;
  }

  void moveE(){
    temp=_1;
    _1=_4;
    _4=_6;
    _6=_3;
    _3=temp;
  }

  void moveW(){
    temp=_1;
    _1=_3;
    _3=_6;
    _6=_4;
    _4=temp;
  }

  void moveS(){
    temp=_1;
    _1=_5;
    _5=_6;
    _6=_2;
    _2=temp;
  }

  void spin(){
    temp=_2;
    _2=_3;
    _3=_5;
    _5=_4;
    _4=temp;
  }

};int main(){
   
  dice d[100];
  int i,j,k,l,n;  
   
  cin>>n;
   
  for(i=0; i<n; i++)cin>>d[i]._1>>d[i]._2>>d[i]._3>>d[i]._4>>d[i]._5>>d[i]._6;
   
  for(i=0; i<n; i++)for(j=0; j<n; j++){
      if(j==i)continue;  
      
      for(k=0; k<6; k++){
 
    if(k==4)d[i].moveE();
    if(k==5){
      d[i].moveE();
      d[i].moveE();
    }
     
    for(l=0; l<4; l++){
      d[i].spin();
      if(d[i]._1==d[j]._1 &&
         d[i]._2==d[j]._2 &&
         d[i]._3==d[j]._3 &&
         d[i]._4==d[j]._4 &&
         d[i]._5==d[j]._5 &&
         d[i]._6==d[j]._6){
        cout<<"No"<<endl;
        return 0;
      }
    }
 
      }
       
    }
       
   
  cout<<"Yes"<<endl;
   
  return 0;
   
}

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

int main() {
  int n;
  cin >> n;
  int a[] = {1, 2, 4, 8, 16, 32, 64, 128};
  rep(i,8) {
    if (a[i] > n) {
      cout << a[i - 1] << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n;
  int dem=0;
  int ans=0;
  cin>>n;
  int k[n];
  for(int i=0 ; i<n ; i++) {
    cin>>k[i];
  }
  for(int i=0 ; i<n ; i++) {
    if(k[i]>=k[i+1]) dem++;
        else {ans=max(dem,ans);
        dem=0;}
  }
  cout<<ans;
}

Measured memory_bytes: 1024
N = gets.chomp.to_i
str = gets.split
a = Array.new(N)
for i in 0...N do
    a[i] = str[i].to_i
end
a.reverse!
for i in 1...N do
    if a[i]-1 > a[i-1]
        puts "No"
        exit
    elsif a[i]-1 == a[i-1]
        a[i] -= 1
    end
end
puts "Yes"

Measured memory_bytes: 8580
N,M=map(int,input().split())

S=[]

for m in range(M):
	inp=list(map(int,input().split()))
	K=inp[0]
	S.append(inp[1:])

P=list(map(int,input().split()))

allOnCnt = 0

for i in range(2**N):
	tmpS=[0]*N
	for j in range(N):
		if ((i >> j) & 1):
			tmpS[N - 1 - j] = 1

	# print(tmpS)
	allOn = True
	for m in range(M):
		if allOn == False:
			break
		nSwtVal = 0
		for n in range(N):
			if tmpS[n] == 0:
				continue
			if (n+1) in S[m]:
				nSwtVal += 1
		# print(nSwtVal,P[m])
		if nSwtVal % 2 != P[m]:
			allOn = False
			break

	if allOn:
		allOnCnt += 1


print(allOnCnt)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
struct X
{
	int pos,i;
	friend bool operator < (X a,X b){return a.pos<b.pos;}
} x[505];
int ans[250005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x[i].pos),x[i].i=i;
	sort(x+1,x+n+1);
	int p=1;
	for(int i=1;i<=n;i++)
	{
		ans[x[i].pos]=x[i].i;
		for(int j=1;j<=x[i].i-1;j++)
		{
			while(ans[p]&&p<x[i].pos) p++;
			if(p==x[i].pos){printf("No");return 0;}
			ans[p++]=x[i].i;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(p<=x[i].pos-1&&!ans[p]){printf("No");return 0;}
		for(int j=1;j<=n-x[i].i;j++)
		{
			while(ans[p]) p++;
			ans[p++]=x[i].i;
		}
		//if(i<n&&p<x[i+1].pos-1){printf("No");return 0;}
	}
	printf("Yes\n");
	for(int i=1;i<=n*n;i++) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int rank(int **A, int N){
	int i, j, k, l, *tmp;
	for(i = 0, j = 0; j < N; j++){
//		printf("(i, j) = (%lld, %lld)\n", i, j);
		for(k = i; k < N && A[k][j] == 0; k++);
//		printf("k = %lld\n", k);
		if(k == N){
			continue;
		}
		tmp = A[i];
		A[i] = A[k];
		A[k] = tmp;
		for(k = 0; k < N; k++){
			if(i == k || A[k][j] == 0){
				continue;
			}
			for(l = j; l < N; l++){
				A[k][l] ^= A[i][l];
			}
		}
		i++;
	}
	return i;
}

signed main(){
	int N, R, i, j, k;
	scanf("%lld", &N);
	int **C = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		C[i] = (int *)malloc(sizeof(int) * N);
		for(j = 0; j < N; j++){
			scanf("%lld", &C[i][j]);
		}
	}
	R = rank(C, N);
//	printf("R = %lld\n", R);

	int *pow2 = (int *)malloc(sizeof(int) * (N * N + 1));
	pow2[0] = 1;
	for(i = 1; i <= N * N; i++){
		pow2[i] = MOD(pow2[i - 1] * 2);
	}

	int ***dp = (int ***)malloc(sizeof(int **) * (N + 1));
	for(i = 0; i <= N; i++){
		dp[i] = (int **)malloc(sizeof(int *) * (N + 2));
		for(j = 0; j <= N + 1; j++){
			dp[i][j] = (int *)malloc(sizeof(int) * (N + 2));
			for(k = 0; k <= N + 1; k++){
				dp[i][j][k] = 0;
			}
		}
	}
	dp[0][0][0] = 1;
	for(i = 0; i < N; i++){
		for(j = 0; j <= N; j++){
			for(k = 0; k <= N; k++){
				if(k > R || j < k){
					dp[i][j][k] = 0;
				}
				else{
					dp[i + 1][j][k] = MOD(dp[i + 1][j][k] + pow2[j] * dp[i][j][k]);
					dp[i + 1][j + 1][k] = MOD(dp[i + 1][j + 1][k] + MOD(pow2[N] - pow2[R - k + j]) * dp[i][j][k]);
					dp[i + 1][j + 1][k + 1] = MOD(dp[i + 1][j + 1][k + 1] + MOD(pow2[R - k + j] - pow2[j]) * dp[i][j][k]);
				}
			}
		}
	}
/*	for(i = 0; i <= N; i++){
		for(j = 0; j <= N; j++){
			for(k = 0; k <= N; k++){
				printf("dp[%lld][%lld][%lld] = %lld\n", i, j, k, dp[i][j][k]);
			}
		}
		printf("\n");
	}
*/	int ans = 0;
	for(j = 0; j <= N; j++){
		ans = MOD(ans + pow2[N * (N - j)] * dp[N][j][R]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 218240
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    dif = B[i] - A[i]
    if dif > 0:
        ans += A[i]
        ans += min(A[i + 1], dif)
        A[i + 1] = max(A[i + 1] - dif, 0)
    else:
        ans += B[i]
print(ans)

Measured memory_bytes: 18624
N = int(input())
P = [int(i) for i in input().split()]

P_origin = P[:]
P.sort()

diff_count = 0
for i in range(N):
  if P_origin[i] != P[i]:
    diff_count +=1

if diff_count <= 2:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 3060
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ; 
long long n,k;
vector<long long>h;
long long INF=1e9+10;
long long dx[100010];
long long dp(long long x){
	debug() << imie(x);
	if(x>=n)return INF;
	if(x==n-1)return 0;
	if(dx[x]!=-1)return dx[x];
	long long ans=INF;
	for(int i=1;i<=k;i++){
		if(x+i<n)
		ans=min(ans,abs(h[x]-h[x+i])+dp(x+i));
	}
	// long long ans=min(choice2,choice1);
	return dx[x]=ans;
}
int main(){
	fastio;
	cin>>n>>k;
	memset(dx,-1,sizeof dx);
	h.resize(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	debug() << imie(h);
	cout<<dp(0)<<endl;
}	

Measured memory_bytes: 6528
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def check(s):
    for i in range(len(s)):
        if s[i] != s[len(s)-1-i]:
            return False
    return True

def main():
    n = input()
    for c in n:
        if c == '7':
            print("Yes")
            return
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9064
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n, a;
	cin >> n >> a;
	int amari = n % 500;
	if (amari > a) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

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

int main(){
  long long n,a,b;
  cin >> n >> a >> b;
  if((b-a)%2==0){
    cout << (b-a)/2 << "\n";
  }else{
	if((n-a)>=(b-1)){
      cout << min((b-1),((a+b-1)/2)) << "\n";
    }else{
      cout << min((n-a),(2*n-a-b+1)/2) << "\n";
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 500005
#define LAX 5000005

pair<int, pair<int,int> >pr[MAX];
int Tree[MAX], ans[MAX];
int p[LAX];

int query(int idx)
{
    int sum = 0;
    while(idx>0)
    {
        sum+=Tree[idx];
        idx-=idx&(-idx);
    }
    return sum;
}

void update(int idx, int x)
{
    while(idx<MAX)
    {
        Tree[idx]+=x;
        idx+=idx&(-idx);
    }
}

int main()
{
    int n, q; ///number of element
    cin>>n>>q;
    int a[n+5];
    for(int i = 1; i <= n; i++)
        cin>>a[i];
    int x = 1; ///number of query
    ///cin>>q;
    for(int i = 1; i <= q; i++)
    {
        cin>>pr[i].second.first>>pr[i].first;
        pr[i].second.second = i;
    }
    sort(pr+1, pr+q+1);
    memset(Tree, 0, sizeof(Tree));
    memset(p, -1, sizeof(p));
    for(int i = 1; i <= n; i++)
    {
        if(p[a[i]]!=-1)
            update(p[a[i]],-1);
        p[a[i]] = i;
        update(i,1);
        while(x<=q && pr[x].first==i)
        {
            ans[pr[x].second.second] = query(pr[x].first) - query(pr[x].second.first-1);
            x++;
        }
    }
    for(int i = 1; i <= q; i++)
        cout<<ans[i]<<endl;
    return 0;
}
/*
8
1 1 1 2 3 5 1 2
5
1 8
2 3
3 6
4 5
4 8
*/


Measured memory_bytes: 35012
n = int(input())
h = list(map(int, input().split()))

ans = 0
tmp = 0

for i in range(1, n) :
    if h[i] <= h[i - 1] :
        tmp += 1
    else :
        if tmp >= ans :
            ans = tmp
        tmp = 0


print(max(ans, tmp))

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll l,r; cin>>l>>r;
  ll ans=LINF;
  irep(i,l,min(r,l+2019LL)){
    ireps(j,i+1,min(r,l+2019LL)){
      chmin(ans,i*j%2019);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(nlgk)=O(n).
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from fractions import gcd                    # for Python3.4.3
from itertools import product

def main():
    mod = 10000007                  # 10^9+7
    inf = float('inf')
    input = sys.stdin.readline      # 改行文字が残ることに注意
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def ii():  return int(input())
    def mi():  return map(int, input().rstrip().split())
    def lmi(): return list(map(int, input().rstrip().split()))
    def li():  return list(input().rstrip())
    
    
    n, m = mi()
    x = [0] * n
    y = [0] * n
    z = [0] * n
    for i in range(n):
        L = lmi()
        x[i] = L[0]
        y[i] = L[1]
        z[i] = L[2]
    ans = 0
    cost = [0] * n
    for f_list in product([lambda x: x, lambda x: -x], repeat=3):
        for i in range(n):
            cost[i] = f_list[0](x[i]) + f_list[1](y[i]) + f_list[2](z[i])
        cost.sort(reverse=True)
        ans = max(ans, sum(cost[:m]))
    print(ans)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <stdio.h>

int main()
{
	char A[200001];
	scanf("%s", A);
	
	int i, j, count[26] = {};
	long long ans = 1;
	for (i = 0; A[i] != 0; i++) {
		count[A[i] - 'a']++;
		for (j = 0; j < 26; j++) if (j != A[i] - 'a') ans += count[j];
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 384