akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long
using namespace std;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    string S_r = S;
    reverse(S_r.begin(),S_r.end());
    bool flag = true;
    if(S != S_r) flag = false;
//    cout << S_r << endl;

    string sub1 = S.substr(0,(N - 1) / 2);
    string sub1_r = sub1;
    reverse(sub1_r.begin(),sub1_r.end());
    if(sub1 != sub1_r) flag = false;

    string sub2 = S.substr((N + 1) / 2);
    string sub2_r = sub2;
    reverse(sub2_r.begin(),sub2_r.end());
    if(sub2 != sub2_r) flag = false;

//    cout << sub1 << " " << sub1_r << " " << sub2 << " " << sub2_r << endl;
    cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
 
using namespace std;
 
int main() {
    int i,j;
    char buf;
    
    while(1){
        cin.get(buf);
        
        //???????????¶
        if ( buf == '\n' ) break;
        
        if(islower(buf)) cout << (char)toupper(buf);
        else if(isupper(buf)) cout << (char)tolower(buf);
        else cout << buf;
    }
    cout << endl;
    
    return 0;
}

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

int main(){
	double N,K;
  double max = 0,sum = 0,p = 0,point = 0;
  cin >> N >> K;
  vector<double> dise(N);
  vector<double> c(N);
  for(double i = 0;i < N;i++){
    cin >> dise.at(i);
 	
    c.at(i) = (dise.at(i) + 1) / 2 ;
  }
  
  for(int i = 0;i < N;i++){
      sum += dise.at(i);
    if(i >= K - 1){
      if(sum > max){
        max = sum;
        p = i;
      }
   	sum -= dise.at(i - (K - 1));
    }
  }
  for(int i = p;i > p - K ;i--){
    point += c.at(i);
  }
  printf("%.40f",point);
return 0;
}

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

using namespace std;

int main(){
  string s[3];
  s[0] = "Sunny";
  s[1] = "Cloudy";
  s[2] = "Rainy";
  
  string input;
  cin >> input;
  for(int i = 0; i < 3; i++){
    if(s[i] == input){
      if(i == 2)
        cout << s[0];
      else
        cout << s[i + 1];
    }
  }
  
  return 0;
}

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

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    string S, T;
    cin >> S >> T;
    int maxm=0;
    rep(i, S.length()-T.length()+1){
        int m = 0;
        rep(j, T.length()){
            if(S.at(i+j)==T.at(j)) m++;
        }
        maxm = max(maxm, m);
    }
    out(T.length()-maxm);
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 3652
// Problem : A - AC or WA
// Contest : AtCoder Beginner Contest 152
// URL : https://atcoder.jp/contests/abc152/tasks/abc152_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a, b; cin >> a >> b;
	if(a == b) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    ll N;
    cin >> N;
    if(N <= 999) { printf("ABC\n"); }
    else { printf("ABD\n"); }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first < another.first;
}

int main()
{
    std::string word;
    std::string w = "Yes";
    int64_t a,b,c,d,e,f;
    std::cin>> a;

    std::vector< int64_t > result;
    std::vector< std::vector< int64_t > > list;
    bool finish = false;
    int64_t all = 0;
    int64_t check = 0;

    while( all < a )
    {
        std::vector< int64_t > instance( 10, 0 );
        
        for( int i = 0; i < 10; i++ )
        {
            if( list.empty() )
            {
                instance[i] = 1;
            }
            else
            {
                for( int r = std::max( i - 1, 0 ); r <= std::min( i + 1, 9 ); r++ )
                {
                    instance[i] += list[check-1][r];
                }
            }

            if( i != 0 )
            {
                all += instance[i];
            }

            if( a <= all )
            {
                a -= ( all - instance[i] );                
                result.push_back( i );
                break;
            }
        }

        list.push_back( instance );
        check += 1;
    }

    for( int i = check - 2; i >= 0; i-- )
    {
        all = 0;
        int cc = result.back();
        
        for( int r = std::max( cc - 1, 0 ); r <= std::min( 9 ,cc + 1 ); r++ )
        {
            all += list[i][r];

            if( a <= all )
            {
                result.push_back( r );
                a -= ( all - list[i][r] );
                break;
            }
        }
    }

    for( int i = 0; i < result.size(); i++ )
    {
        std::cout<< result[i];
    }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

int gcd(int a, int b){
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main(){
	ll a, b;
	cin >> a >> b;
	int ans = a + b;
	if(ans >= 24) ans -= 24;
	cout << ans << endl;
}

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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

#define REP(i,n) for(i=0;i<n;i++)

int gcd(int a,int b);

int main(void)
{
  int i,n;
  int l[10] = {0};
  scanf("%d",&n);
  int max=0,sum=0;
  REP(i,n)
  {
    scanf("%d",&l[i]);
    sum += l[i];
    if(max<l[i]) max = l[i];
  }
  if((sum-max)>max) printf("Yes");
  else printf("No");
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MAX 200005

using namespace std;

int main() {
    int a, b, c, k; 
    
    cin >> a >> b >> c >> k;
    
    int ans = 0;
    while (a > 0 && k > 0) {
        ans++;
        a--;
        k--;
    }
    while (k > 0 && b > 0) {
        b--; 
        k--;
    }
    while (k > 0 && c > 0) {
        ans--;
        c--;
        k--;
    }
    
    cout << ans << "\n";
  
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
int main(){
int a,b;
scanf("%d%d",&a,&b);
if(b<10)a=10*a+b;
else if(b<100)a=a*100+b;
else a=a*1000+b;
for(int i=1;i<=10000;i++){
if(i*i==a){
printf("Yes\n");
break;
}
if(i==10000)printf("No\n");
}
return 0;
}


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

int a[200000];
int used[200000];

int main() {
  ll n, k;
  cin >> n >> k;
  rep(i, n) {cin >> a[i]; a[i]--; used[i] = false;}

  if (n >= k) {
    int i = 0;
    rep(l, k) {
      i = a[i];
    }
    cout << i+1 << endl;
    return 0;
  }
  
  ll i = 0, s = 0, m = 0;
  while ((!used[m]) && (i < n)) {
    i++;
    used[m] = true;
    m = a[m];
  }

  ll j = 0; s = m;
  while (a[m] != s) {
    m = a[m];
    j++;
  }
  j++;
  k -= i;
  k %= j;
  
  rep(j, k) {s = a[s];}
  cout << s+1 << endl;
  return 0;
}


Measured memory_bytes: 5156
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    string s,t;cin>>s>>t;
    for(int i=(s.size()-t.size());i>=0;i--){
        string ps=s.substr(i,t.size());
        //cout<<ps<<endl;
        bool jud=true;
        rep(j,t.size())if(ps[j]!=t[j]&&ps[j]!='?'){
            jud=false;break;
        }
        if(jud){
            rep(j,t.size())s[i+j]=t[j];
            rep(j,s.size())if(s[j]=='?')s[j]='a';
            cout<<s<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE"<<endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=200010,SH=19,SN=1<<SH,INF=0x7f7f7f7f;
int tol[N][SH],tor[N][SH];
int fl[SN],fr[SN];
int x[N],v[N];
int ext[N];
int main(){
	int n=ni,vs=0;
	v[0]=ni;
	for(int &i=vs;v[i];i++){
		v[i+1]=v[i]>>1;
	}
	for(int i=1;i<=n;i++){
		x[i]=ni;
	}
	for(int j=0;j<=vs;j++){
		for(int i=1;i<=n;i++){
			tol[i][j]=i>1&&x[i]-x[i-1]<=v[j]?tol[i-1][j]:i;
		}
		for(int i=n;i>=1;i--){
			tor[i][j]=i<n&&x[i+1]-x[i]<=v[j]?tor[i+1][j]:i;
		}
	}
	for(int s=0,ts=1<<vs;s<ts;s++){
		fl[s]=0;
		for(int i=1;i<=vs;i++){
			if((s>>(i-1))&1){
				apmax(fl[s],tor[fl[s^(1<<(i-1))]+1][i]);
			}
		}
	}
	for(int s=0,ts=1<<vs;s<ts;s++){
		fr[s]=n+1;
		for(int i=1;i<=vs;i++){
			if((s>>(i-1))&1){
				apmin(fr[s],tol[fr[s^(1<<(i-1))]-1][i]);
			}
		}
	}
	memset(ext,127,sizeof(ext));
	for(int s=0,ts=1<<vs;s<ts;s++){
		apmin(ext[fl[s]],fr[s^(ts-1)]);
	}
	for(int i=n;i>=1;i--){
		apmin(ext[i-1],ext[i]);
	}
	for(int i=1;i<=n;i++){
		puts(ext[tol[i][0]-1]<=tor[i][0]+1?"Possible":"Impossible");
	}
	return 0;
}

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

vote = dict()
maxv = 0
for i in range(n):
  s = input()
  if not s in vote:
    vote[s] = 1
  else:
    vote[s] += 1
  maxv = max(maxv, vote[s])

candidates = list()

for k, v in vote.items():
  if int(v) == maxv:
    candidates.append(k)

candidates.sort()

for candidate in candidates:
  print(candidate)



Measured memory_bytes: 35364
a, b = map(int, input().split())
cnt=0
for i in range(a,b+1):
    i_lst=[]
    i_lst.append(str(i%10))
    i_lst.append(str(int((i%100)/10)))
    i_lst.append(str(int((i%1000)/100)))
    i_lst.append(str(int((i%10000)/1000)))
    i_lst.append(str(int((i%100000)/10000)))
    i_rvs=list(i_lst)
    i_lst.reverse()
#    print(i_lst, i_rvs)
    if(i_lst==i_rvs):
        cnt+=1
print(cnt)
 


Measured memory_bytes: 3064
#include <stdio.h>
    #include<string.h>
    int main(void) {
      int a,b,c=0,d,i,j,h[1000],cou=0;
      scanf("%d",&a);
      for(i=0;i<a;i++){
          scanf("%d",&h[i]);
      }
      for(i=0;i<a;i++){
          cou=0;
          for(j=0;j<i;j++){
              if(h[i]>=h[j]){
                  cou++;
              }
          }
          if(i==cou){
              c++;
          }
      }
      printf("%d",c);
      
      
      return 0;
    }

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		int z = 1;
		if (x >= y) {
			while(z != 0) {
				z = x % y;
				x = y;
				y = z;
			}
			System.out.println(x);
		}
		else {
			while(z != 0) {
				z = y % x;
				y = x;
				x = z;
			}
			System.out.println(y);
		}
	}
}


Measured memory_bytes: 26280
N = int(input())
A = list(map(int,input().split()))
a_d = {}
for a in A:
    if a in a_d:
        a_d[a] += 1
    else:
        a_d[a] = 1
mysum = sum(A)
#print(a_d)

Q = int(input())
for q in range(Q):
    b, c = map(int,input().split())
    if b in a_d:
        add = a_d[b] 
        #sub = a_d[c]
        mysum = mysum - add*b + add*c
        a_d[b] = 0
        if c in a_d:
            a_d[c] += add
        else:
            a_d[c] = add
    print(mysum)

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

const int N = 2e5 + 10, M = 2e3 + 10, mod = 1e9 + 7;

namespace {
  inline int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
  inline int sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
  inline int mul(int x, int y) { return 1LL * x * y % mod; }
}

int n, f[M << 1 | 1][M << 1 | 1], a[N], b[N], fac[N], ifac[N], inv[N];

int binom(int x, int y) {
  if(x < y) {
    return 0;
  }
  return mul(fac[x], mul(ifac[y], ifac[x - y]));
}

int main(void) {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    f[M - a[i]][M - b[i]]++;
  }
  for(int i = 1; i < M << 1; i++) {
    for(int j = 1; j < M << 1; j++) {
      f[i][j] = add(f[i][j], add(f[i - 1][j], f[i][j - 1]));
    }
  }
  
  fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;
  for(int i = 2; i < M << 4; i++) {
    fac[i] = mul(fac[i - 1], i);
    inv[i] = mul(mod - mod / i, inv[mod % i]);
    ifac[i] = mul(ifac[i - 1], inv[i]);
  }

  int ans = 0;
  for(int i = 1; i <= n; i++) {
    ans = sub(ans, binom(2 * (a[i] + b[i]), 2 * a[i]));
  }
  for(int i = 1; i <= n; i++) {
    ans = add(ans, f[M + a[i]][M + b[i]]);
  }
  ans = mul(ans, mod + 1 >> 1);
  cout << ans << endl;
  return 0;
}


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

const int N = 600;
long long dp[8];
long long bs[N + 7];
long long a[N + 7];

int main() {
	ios_base::sync_with_stdio(0);
	dp[0] = bs[0] = 1;
	
	for(int i = 1; i <= N; ++i) {
		for(int j = 1; j <= 7; ++j) dp[j] += dp[j - 1];
		bs[i] = dp[7];
	}
	
	int ile = 7 * N;
	long long k;
	cin >> k;
	for(int i = N; i > 0; --i) {
		a[i] = k / bs[i];
		k -= a[i] * bs[i];
		ile += a[i];
	}
	
	for(int i = 1; i <= N; ++i) {
		cout << "FESTIVA";
		for(int j = 0; j < a[i]; ++j) cout << 'L';
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 1000000007
#define DEBUG 0

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
	cerr << *it << " = " << a <<" ";
	err(++it, args...);
}


string A[1001];
int dp[1001][1001];
int fun(int i,int j,int h,int w){
	//cout<<x<<" ";
	if(i>=h||j>=w)return 0;
	if(A[i][j]=='#')return dp[i][j]=0;
	if(dp[i][j]!=-1)return dp[i][j];
	if(i==h-1&&j==w-1)return 1;
	return dp[i][j]=(fun(i+1,j,h,w)%MOD+fun(i,j+1,h,w)%MOD)%MOD;
}
int main(){
    //freopen("test.txt", "r", stdin);
    int h,w;cin>>h>>w;
    forn(i,h)cin>>A[i];
    forn(i,h){
    	forn(j,w){
    		dp[i][j]=-1;
    	}
    }
    cout<<fun(0,0,h,w)<<endl;

    return 0;
}



Measured memory_bytes: 5376
#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#define LL long long

using namespace std;

inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}

inline void read(int &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

inline void read(LL &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

int wt,ss[19];
inline void print(int x){
	if (x<0) x=-x,putchar('-'); 
	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}
inline void print(LL x){
	if (x<0) x=-x,putchar('-');
	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}

LL n,m;

int main()
{
    read(n);read(m);    
    LL x,y,z;
	vector<LL> a(m+10);
    for(int i=0;i<n;i++)
	{
		read(x);read(y);
        z=y-x+1;a[0]+=1;a[z]-=1;
        LL t=z+1,s;
        while(t<=m)
		{
            LL v=((x+t-1)/t);
            if((x+t-1)/t<=0) break;
            s=y/((x+t-1)/t);
            if(s>=t) a[t-1]+=1,a[s]-=1;
            if((x+t-1)/t<=1) break;
            t=max(s+1,(x+(v-1)-1)/(v-1));
        }
    }
    LL ans=0;
    for (int i=0;i<m;i++)
    	ans+=a[i],cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
typedef pair<int, int> P;

int H, W;
string board[110];
int dist[110][110];
queue<P> que;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int bfs() {
  queue<P> que;
  que.push(P(0, 0));
  dist[0][0] = 1;
  while (!que.empty()) {
    P cur = que.front();
    que.pop();
    if (cur.first == H - 1 && cur.second == W - 1) break;
    for (int i = 0; i < 4; i++) {
      int nx = cur.first + dx[i];
      int ny = cur.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && board[nx][ny] != '#' &&
          dist[nx][ny] == -1) {
        dist[nx][ny] = dist[cur.first][cur.second] + 1;
        que.push(P(nx, ny));
      }
    }
  }
  return dist[H - 1][W - 1];
}

int main() {
  cin >> H >> W;

  int cnt = 0;
  for (int i = 0; i < H; i++) {
    cin >> board[i];
    for (int j = 0; j < W; j++) {
      if (board[i][j] == '.') cnt++;
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      dist[i][j] = -1;
    }
  }

  if (bfs() > 0) {
    cout << cnt - dist[H - 1][W - 1] << endl;
  } else {
    cout << -1 << endl;
  }
}

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

int main(){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import collections


def solve(X):
    l = [i for i in range(-1000,1000,1)]
    # for n in range(1000):
    #     print("{}**5:{}".format(n,n**5))
    for A in range(1000):
        for B in range(-1000,1000,1):
            if(X == (A**5 - B**5)):
                print(A,B)
                sys.exit()
def main():
    X = int(input())
    solve(X)
    # print(solve())

if __name__ == "__main__":
    main()


Measured memory_bytes: 68136
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
#define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int a,b,c;
  cin>>a>>b>>c;
  if(a == b && b == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend();
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

int main() {
	ll march[] = { 0,0,0,0,0 };
	ll ans = 0;
	makei(N);
	rep(N) {
		string s;
		cin >> s;
		switch (s[0]) {
		case 'M':
			++march[0];
			break;
		case 'A':
			++march[1];
			break;
		case 'R':
			++march[2];
			break;
		case 'C':
			++march[3];
			break;
		case 'H':
			++march[4];
			break;
		}
	}
	FOR(i, 0, 5)FOR(j, i + 1, 5)FOR(k, j + 1, 5) {
		ans += march[i] * march[j] * march[k];
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t gcd(int64_t a, int64_t b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

const int64_t MOD = 1'000'000'007L;

template <typename G>
G dpow(G x, int64_t y) {
  if (y == 0) {
    return (G)1;
  }
  if (y % 2 == 0) {
    return dpow(x * x, y / 2);
  } else {
    return x * dpow(x, y - 1);
  }
}

int64_t inv(int64_t x) { return dpow(x, MOD - 2); }

template <int64_t MOD>
class Modint {
  using Self = Modint<MOD>;

  int64_t m_value;

 public:
  explicit Modint(int64_t value) : m_value(value % MOD) {}
  Self& operator=(const Self& rh) {
    m_value = rh.m_value;
    return *this;
  }
  Self operator-() const { return Self(MOD - m_value); }
  Self operator+(const Self& other) const {
    return Self(m_value + other.m_value);
  }
  Self operator-(const Self& other) const {
    return Self(m_value - other.m_value + MOD);
  }
  Self operator*(const Self& other) const {
    return Self(m_value * other.m_value);
  }
  Self& operator+=(const Self& rh) { return (*this) = (*this) + rh; }
  Self& operator-=(const Self& rh) { return (*this) = (*this) - rh; }
  Self& operator*=(const Self& rh) { return (*this) = (*this) * rh; }
  int64_t value() const { return m_value; }
};

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

  int zeros = 0;
  using P = pair<int64_t, int64_t>;
  map<P, int> a, b;
  rep(i, n) {
    int64_t x, y;
    cin >> x >> y;
    if (x != 0 && y != 0) {
      if (y < 0) {
        x *= -1;
        y *= -1;
      }

      int64_t d = gcd(abs(x), abs(y));
      x /= d;
      y /= d;
      if (x > 0) {
        a[P(x, y)]++;
      } else {
        a[P(y, -x)];
        b[P(y, -x)]++;
      }
    } else {
      if (x == 0 && y == 0) {
        zeros++;
      } else if (x == 0) {
        a[P(1, 0)];
        b[P(1, 0)]++;
      } else {
        a[P(1, 0)]++;
      }
    }
  }

  using Mint = Modint<1'000'000'007L>;
  Mint result(1);
  for (auto p : a) {
    P k;
    int acnt;
    tie(k, acnt) = p;
    int bcnt = b[k];

    Mint term = dpow(Mint(2), acnt) + dpow(Mint(2), bcnt) - (Mint)1;
    result *= term;
  }
  result += (Mint)zeros;
  result -= (Mint)1;
  cout << result.value() << endl;

  return 0;
}

Measured memory_bytes: 28600
n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n-1):
    x, y = a[i], a[i+1]
    if x == i+1:
        ans += 1
        a[i] = y
        a[i+1] = x

if a[n-1] == n:
    ans += 1
    x, y = a[n-2], a[n-1]
    a[n-2] = y
    a[n-1] = x

print(ans)

Measured memory_bytes: 14008
#include <iostream>
#include <string.h>

using namespace std;

int main()
{ 
    string str1, str2;
    int count =0;
    cin>>str1>>str2;
    long long int n = str1.length();
    for(int i=0; i<n; i++)
    {
        if(str1[i]!=str2[i])
        {
            count++;
        }
    }
   cout<<count;
   

    return 0;
}

Measured memory_bytes: 3836
x = int(input())
if 400 <= x and x <= 599:
    print(8)
elif 600 <= x and x <= 799:
    print(7)
elif 800 <= x and x <= 999:
    print(6)
elif 1000 <= x and x <= 1199:
    print(5)
elif 1200 <= x and x <= 1399:
    print(4)
elif 1400 <= x and x <= 1599:
    print(3)
elif 1600 <= x and x <= 1799:
    print(2)
elif 1800 <= x and x <= 1999:
    print(1)

Measured memory_bytes: 9196
h = [[[0]*10 for i in range(3)] for j in range(4)]
n = int(input())
for i in range(n):
    b,f,r,v = map(int,input().split())
    h[b-1][f-1][r-1] += v

s = ""
for i in range(4):
    for j in range(3):
        for k in range(10):
            s += " " + str(h[i][j][k])
        s += "\n"
    if i < 3:
        s += "####################\n"

print(s,end="")

Measured memory_bytes: 7616
a=input()
for i in range(8):
  b=bin(i)[2:]
  b="q"+"0"*(3-len(b))+b
  b=b.replace("0","-").replace("1","+")
  xv="".join([d+s for s,d in zip(a,b)])
  xv=xv[1:]
  if eval(xv)==7:
    print(xv,"=7",sep="");break

Measured memory_bytes: 3064
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    string cmd;
    ll num;
    priority_queue<ll> Q;
    cin >> cmd;

    while (cmd != "end") {
        if (cmd == "insert") {
            cin >> num;
            Q.push(num);
        }

        if (cmd == "extract") {
            cout << Q.top() << endl;
            Q.pop();
        }
        cin >> cmd;
    }
}


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

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

    vector<int> A(N + 1, 0);
    for (int i = 2; i <= N; i++) {
        int tmp;
        cin >> tmp;
        A[tmp]++;
    }

    for (int i = 1; i <= N; i++) {
        cout << A[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
 
using ll=long long; 
 
void solve(){
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<int>a(n),b(m);
	for(int i=0; i<n; i++)cin>>a[i];
	for(int i=0; i<m; i++)cin>>b[i];
	a.push_back(x);
	b.push_back(y);
	for(int i=0; i<a.size(); i++){
		for(int j=0; j<b.size(); j++){
			if(b[j]<=a[i]){
				cout<<"War"<<endl;
				return;
			}
		}
	}
	cout<<"No War"<<endl;
}
 
signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 101

int main(){
  int i,j,n,u,k,v;
  int a[MAX][MAX] = {};

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      a[u][v] = 1;
    }
  }

  for(i = 1; i <= n; i++){
    for(j = 1; j < n; j++){
      printf("%d ",a[i][j]);
    }
    printf("%d\n",a[i][n]);
  }

  return 0;
}



Measured memory_bytes: 2108
import collections


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    M = int(input())
    T = [input() for _ in range(M)]
    S = collections.Counter(S)
    T = collections.Counter(T)

    Mcnt = 0
    for s, ns in S.items():
        cnt = 0
        if s in list(T.elements()):
            if T[s] < ns:
                cnt = ns - T[s]
        else:
            cnt = ns

        if cnt > Mcnt:
            Mcnt = cnt

    print(Mcnt)


main()


Measured memory_bytes: 3436
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
a = LIST()

lim = 10**5+3
cnt = [0]*lim

for n in a:
	cnt[n] += 1

ans = 0
for i in range(2, lim):
	ans = max(ans, cnt[i-2]+cnt[i-1]+cnt[i])
print(ans)

Measured memory_bytes: 15956
import java.util.*;
public class Main {
      public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();
      int ans ;
      if(a<b){ans=a;}else{ans=b;}
      if(c<d){ans=ans+c;}else{ans=ans+d;}
      System.out.println(ans);
   }
 }

Measured memory_bytes: 23380
#include<stdio.h>

int main(){
  int a,b,c,x;
  int i,j,k,ans=0;

  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  scanf("%d", &x);

  for(i=0; i<=a; i++){
    for(j=0; j<=b; j++){
      for(k=0; k<=c; k++){
        if(x==i*500+j*100+k*50){
          ans++;
        }
      }
    }
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 128
/******************************************************************************
 
                                Bungee_Gum  &&  Z1H
 
*******************************************************************************/
 
#include <bits/stdc++.h>
#include <algorithm>
#include <cstring>
#define forn(i,n) for(int i=0;i<(int)n ;i++)
#define fors(i,s) for(int i=0;i<s.length() ;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
using namespace std;
typedef long long ll;
double n;
double a[300005];
double dp[3000][3000];
double solve(int idx,int H){
    if(dp[idx][H]!= (double)-1)return dp[idx][H];
    if(idx>=n){
        
       if(n-H<H)return 1;
       
       return 0;
        
    }
    
    double res1=1;
    
    res1 += solve(idx+1,H+1)*a[idx];
    res1 +=solve(idx+1,H)*(1-a[idx]);
    
    return dp[idx][H]  = res1;
    
    
}
int main()
{
    for(int i=0;i<3000;i++)
        for(int j=0;j<3000;j++)dp[i][j]=-1;
    cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
cout<<fixed<<setprecision(10)<<solve(0,0)-n;
    return 0;
}


Measured memory_bytes: 72064
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

mm = 1000000007
n, m = na()
ai = [-1]
for i in range(m):
    ai.append(int(input()))
ai.append(n+1)
li = [1, 1]
for i in range(n+4):
    li.append(li[i] + li[i+1])
ans = 1
#print(li)
if m == 0:
    print(li[n] % mm)
else:
    for i in range(len(ai) - 1):
        if ai[i+1] - ai[i] == 1:
            ans = 0
            break
        else:
            ans *= li[(ai[i+1] - ai[i]) - 2]
            ans = ans % mm
    print(ans)

Measured memory_bytes: 464036
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define sll set<ll>
#define ins insert
#define rep(i,n) for(int i=0;i<n;i++)
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define gp " ";
#define MAX 9999999
#define MOD 1000000007
#define mnn(v2) *min_element(v2.begin(),v2.end());
#define mxx(v2) *max_element(v2.begin(),v2.end());
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,i,j,k,c=0,mx=0;
        cin>>n;
        string s;
        map<string,ll>m;
        for(i=0; i<n; i++)
        {
            cin>>s;
            m[s]++;
        }

        map<string,ll>:: iterator itr;
        for (itr = m.begin(); itr != m.end(); ++itr)
        {
               if(itr->second>=mx)
                    mx=itr->second;

        }
        for (itr = m.begin(); itr != m.end(); ++itr)
        {
               if(itr->second==mx)
                   cout<<itr->first<<endl;

        }

    }
}


Measured memory_bytes: 19244
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 0

ll a[200010];
int main() {
   int n;
   ll sum = 0;
   cin >> n;
   for (int i = 1 ; i <= n ; ++i) {
      cin >> a[i];
      sum += a[i];
   }
   ll mn = INF * 1000000ll, curr = 0;
   for (int i = 1 ; i < n ; ++i) {
      curr += a[i];
      mn = min (mn, abs(2 * curr - sum));
   }
   cout << mn << endl;

   return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll m = n%k;
    cout << min(m, abs(m-k));
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  int N, M; cin >> N >> M;
  vector<int> u[N*3], v[N*3];
  rep(i,M) {
    int tu, tv; cin >> tu >> tv; tu--; tv--;
    rep(j,3) u[tu+N*j].push_back(tv+N*((j+1)%3));
  }
  int S, T; cin >> S >> T; S--; T--;
  int d[N*3]={}; fill_n(d,N*3,-1); d[S]=0;
  queue<int> ver; ver.push(S);
  while (!ver.empty()) {
    int now = ver.front(); ver.pop();
    for (auto x: u[now]) {
      if (d[x]==-1) {
        d[x]= d[now]+1;
        ver.push(x);
      }
    }
    // cout << now << endl;
  }
  int result = (d[T]==-1) ? -1 : d[T]/3;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 24832
class Node:
    __slots__ = ["data", "next", "prev"]
    def __init__(self, data):
        self.data = data
        self.next = None
        self.prev = None

class Queue:
    __slots__ = ["head", "tail"]
    def __init__(self):
        self.head = None
        self.tail = None
    
    def appendleft(self, data):
        node = Node(data)
        self.head, node.next = node, self.head
        if self.tail:
            node.next.prev = self.head
        else:
            self.tail = node
    
    def pop(self):
        if self.tail:
            target, self.tail = self.tail, self.tail.prev
            if self.tail:
                self.tail.next = None
            return target.data

def simulate_round_robin_scheduling(x, y):
    total_time = 0
    while y.tail:
        name, time = y.pop()
        time = int(time)
        total_time += min(time, x)
        time -= x
        if time > 0:
            y.appendleft([name, time])
        else:
            print("{} {}".format(name, total_time))
if __name__ == "__main__":
    n, q = map(int, input().split())
    processes = Queue()
    for _ in range(n):
        processes.appendleft(input().split())
    simulate_round_robin_scheduling(q, processes)


Measured memory_bytes: 19500
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] a = new int[n];
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(in.readLine());
    }
    
    int[] a_sort = a.clone();
    Arrays.sort(a_sort);
    
    if(n==1) {
      System.out.println(a_sort[0]);
      return;
    }
    
    for(int i=0; i<n; i++) {
      System.out.println(a_sort[n-1]!=a[i]?a_sort[n-1]:a_sort[n-2]);
    }
  }
}

Measured memory_bytes: 60036
#include "bits/stdc++.h"
using namespace std;
int n;
int a[300010];
int l[300010], r[300010];
const int mod = 998244353;


int id(int x) {
	return ((x % n) + n) % n;
}
int size(int l, int r) {
	if(l == -1) return 0;
	int ans = 0;
	while(true) {
		int tmp = l;
		l = id(l + 1);
		++ans;
		if(tmp == r) break;
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int shift = count(a, a + n, 1);
	if(shift == 0) {
		printf("0\n");
		exit(0);
	} else if (shift == n) {
		long long ans = 1;
		for(int i = 2; i <= n; i++) {
			ans *= i;
			ans %= mod;
		}
		printf("%lld\n", ans);
		exit(0);
	}
	int cur;	
	for(int i = 0; i < n; i++) {
		if(a[i] == 1) {
			cur = i;
			break;
		}
	}
	while(a[id(cur - 1)] == 1) {
		cur = id(cur - 1);
	} 
	memset(l, -1, sizeof l);
	memset(r, -1, sizeof r);

	while(true) {
		int val = a[cur];
		if(l[val] != -1) {
			printf("0\n");
			exit(0);
		}
		int tmp = cur;
		while(a[cur] == val) {
			cur = id(cur + 1);
		}
		l[val] = tmp;
		r[val] = id(cur - 1);
		if(a[cur] == 1) break; 
	}

	for(int i = 1; i <= n; i++) {
		// printf("%d %d %d\n", i, l[i], r[i]);
		if(size(l[i], r[i]) > shift) {
			printf("0\n");
			exit(0);
		} 
	}
	long long ans = 1;
	int cmp = 0;
	int tot = 0;
	for(int i = 1; i <= n; i++) {
		if(l[i] == -1) {
			ans *= (tot - (shift - 1) * cmp - (i - 1));
			ans %= mod;
			continue;
		}
		int sz = size(l[i], r[i]);
		if(a[id(l[i] - 1)] > i) {
			if(a[id(r[i] + 1)] > i) {
				++cmp;
				if(sz < shift) {
					printf("0\n");
					exit(0);
				}
			}
		} else if (a[id(r[i] + 1)] > i) {
		} else {
			--cmp;
			ans *= (shift - sz + 1);
			ans %= mod;
		}
		tot += sz;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3712
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
P = np.array(read().split(),np.int32)

Q = np.minimum.accumulate(P)

answer = np.count_nonzero(P <= Q)

print(answer)


Measured memory_bytes: 22676
n = int(input())
l = list(map(int,input().split()))

dp = [0 for i in range(n)]

dp[1] = abs(l[0] - l[1])


for i in range(2, n):
    dp[i] = min(abs(l[i]-l[i-2])+dp[i-2], abs(l[i]-l[i-1])+dp[i-1])


print(dp[-1])

Measured memory_bytes: 13980
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <iomanip>
#include <map>
#include <sstream>
#define ll long long
using namespace std;
string ent="\n";
string space=" ";
int main(){
   ios_base::sync_with_stdio(false);
   ll n;
   cin >> n;

   if(n%2==1)  cout << 0 << ent;
   else{
      ll div=1;
      ll total=n/10;
      n/=10;
      for(ll i=0;i<=100;i++){
         div = div * 5;
         total += n / div;
         if(n<div)   break;
      }
      cout << total << '\n';
   }
}
/*


*/

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

int N;
long double X[1 << 18], Y[1 << 18];
char C[1 << 18];

long double solve(long double v) {
	long double lx = 1e9, ly = 1e9, rx = -1e9, ry = -1e9;
	
	for (int i = 0; i < N; i++) {
		long double cx = X[i], cy = Y[i];
		if (C[i] == 'L') cx -= v;
		if (C[i] == 'R') cx += v;
		if (C[i] == 'D') cy -= v;
		if (C[i] == 'U') cy += v;
		lx = min(lx, cx); rx = max(rx, cx);
		ly = min(ly, cy); ry = max(ry, cy);
	}
	return (rx - lx) * (ry - ly);
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i] >> C[i];
	}

	long double cl = 0.0, cr = 1e9, c1, c2, minx = 1e18;
	for (int i = 0; i < 130; i++) {
		c1 = (cl + cl + cr) / 3.0;
		c2 = (cl + cr + cr) / 3.0;
		long double p1 = solve(c1);
		long double p2 = solve(c2);
		if (p1 < p2) { cr = c2; minx = min(minx, p1); }
		else { cl = c1; minx = min(minx, p2); }
	}
	printf("%.13Lf\n", minx);
	return 0;
}

Measured memory_bytes: 3968
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  int count=0;
  int D1,D2;
  string ans="No";
  for(int i=0;i<N;++i){
    cin >> D1 >> D2;
    if(D1==D2) count++;
    else count=0;
    if(count==3){
      ans="Yes";
    }
  }

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


Measured memory_bytes: 3620
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

const INF: isize = 999999;

fn main() {
    let n: usize;
    input!(n);
    let mut red = vec![];
    let mut blue = vec![];
    for _ in 0..n {
        let (a, b): (isize, isize);
        input!(a, b);
        red.push((a, b, true));
    }
    for _ in 0..n {
        let (a, b): (isize, isize);
        input!(a, b);
        blue.push((a, b, true));
    }

    red.sort();
    blue.sort();

    let mut ans = 0;
    for &(bx, by, bf) in &blue {
        let (mut bufx, mut bufy, mut bufi) = (INF, -1, INF);
        let mut i = 0;
        for &(rx, ry, rf) in red.iter() {
            if rx < bx && ry < by && bufy < ry && rf {
                bufi = i;
                bufx = rx;
                bufy = ry;
            }
            i += 1;
        }
        if bufi != INF {
            ans += 1;
            red[bufi as usize].2 = false;
        }
    }
    p(ans);
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

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

int n;
int S[105];
ll K;

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&S[i]);
	sort(S,S+n);
	printf("%d\n",S[n-1]-S[0]);
	return 0;
}


Measured memory_bytes: 128
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
 
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
 
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}



int main(){
    int n,i,j,k,K,T,m;
    scanf("%d",&n);
    ll ans=0;
    ll dp[2],f[2];
    dp[0]=0,dp[1]=-1;
    rep(i,0,n){
        scanf("%d",&k);
        if(k==0){
            ans+=max(dp[0],dp[1]);
            dp[0]=0,dp[1]=-1;continue;
        }
        f[0]=f[1]=-1;
        if(dp[0]!=-1){
            Max(f[k&1],dp[0]+k/2);
        }
        if(dp[1]!=-1){
            if(k%2==0){
                Max(f[1],dp[1]+k/2);
            }
            else{
                Max(f[1],dp[1]+k/2);
                Max(f[0],dp[1]+(k+1)/2);
            }
        }
        dp[0]=f[0],dp[1]=f[1];
    }
    printf("%lld\n",ans+=max(dp[0],dp[1]));
    return 0;
}

Measured memory_bytes: 256