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

int main() {

    int N;
    cin >> N;

    int A[100010];
    rep(i, N) cin >> A[i];

    int ans = 1;

    bool up = false;
    bool down = false;

    for (int i = 1; i < N; ++i)
    {
        int dif = A[i] - A[i-1];
        if (dif > 0) up = true;
        if (dif < 0) down = true;
        if (up && down) {
            ans++;
            up = down = false;
            continue;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4004
n, m = map(int, input().split())
l = [0] * n
r = []
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        r.append(b)
    if b == n:
        l[a - 1] = 1
ans = "IMPOSSIBLE"
for i in r:
    if l[i - 1] == 1:
        ans = "POSSIBLE"
print(ans)

Measured memory_bytes: 8644
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int n, a, b, x[N];
int aa, bb;
string _x;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> _x;
  int c=0;
  FOR(i, 0, n){
    x[i] = _x[i]-'0';
    c += x[i];
  }
  a = c-1;
  if(a) FOR(i, 0, n) aa = (aa*2+x[i])%a;
  b = c+1;
  FOR(i, 0, n) bb = (bb*2+x[i])%b;

  FOR(i, 0, n){
    int e, ee, d, p=1;
    if(x[i]){
      e = a, ee=aa;
      if(!e){
        cout << 0 << endl;
        continue;
      }
      d = (ee-modPow(2, n-i-1, e)+e)%e;
    }else{
      e=b, ee=bb;
      d = (ee+modPow(2, n-i-1, e))%e;
    }
    while(d){
      d = d%pcnt(d);
      p++;
    }
    cout << p << endl;
  }
}

Measured memory_bytes: 4500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {


    public static void main(String args[] ) throws IOException {

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

        String[] NUMBER = br.readLine().split(" ");
        DICE dice = new DICE(NUMBER);
        String[] ORDER = br.readLine().split("");

        for(int i = 0;i < ORDER.length ; i++){
    	   Roll_Dice.Roll(ORDER[i] , dice);
        }


        System.out.println( dice.surface[0] );

    }



}


class DICE{

	int[] surface = new int[6];

    DICE(String[] number){                              //0: ?????¢
                                                        //1: ??£??¢
    	for(int i = 0; i < 6;i++ ){                    //2: ?????¢
    		surface[i] = Integer.parseInt(number[i]);  //3: ?????¢
    	}                                               //4: ?????¢
                                                        //5: ?????¢
    }




}


class Roll_Dice{


	static void Roll(String order , DICE dice){



		if( order.equals("S") ){
            int tmp0 = dice.surface[0], tmp1 = dice.surface[1], tmp4 = dice.surface[4], tmp5 = dice.surface[5];
            dice.surface[0] = tmp4;
            dice.surface[1] = tmp0;
            dice.surface[4] = tmp5;
            dice.surface[5] = tmp1;
		}
		else if( order.equals("N") ){
			int tmp0 = dice.surface[0], tmp1 = dice.surface[1], tmp4 = dice.surface[4], tmp5 = dice.surface[5];
            dice.surface[0] = tmp1;
            dice.surface[1] = tmp5;
            dice.surface[4] = tmp0;
            dice.surface[5] = tmp4;

		}
		else if( order.equals("W") ){
			int tmp0 = dice.surface[0], tmp2 = dice.surface[2], tmp3 = dice.surface[3], tmp5 = dice.surface[5];
            dice.surface[0] = tmp2;
            dice.surface[2] = tmp5;
            dice.surface[3] = tmp0;
            dice.surface[5] = tmp3;

		}
		else if( order.equals("E") ){
			int tmp0 = dice.surface[0], tmp2 = dice.surface[2], tmp3 = dice.surface[3], tmp5 = dice.surface[5];
            dice.surface[0] = tmp3;
            dice.surface[2] = tmp0;
            dice.surface[3] = tmp5;
            dice.surface[5] = tmp2;

		}

	}




   void swap_surface(int x , int y){
	   int tmp = x;
	   x = y;
	   y = tmp;

   }


}

Measured memory_bytes: 24628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <set>
//#include <fstream>

#define ll long long int
using namespace std;

void Solve()
{
    string a, b;
    cin >> a >> b;
    if( a.size() < b.size()) cout << "LESS";
    else if(b.size() < a.size()) cout << "GREATER";
    else
    {
        if(a < b) cout << "LESS";
        else if( a > b) cout << "GREATER";
        else cout << "EQUAL";
    }
}

int main()
{
    ios_base::sync_with_stdio( false );
    cin.tie( nullptr );
    //freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
   // int t;
    //cin >> t;
    //while(t--)
    {
        Solve();
        cout << '\n';
    }
    return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=0;
    ll N;
    cin >> N;
    vector<int> s(N);
    rep(i,N) cin >> s[i];
    sort(begin(s), end(s));
    // j < i < l
    rep(i,N) rep(j,i) {
        auto r = lower_bound(begin(s), end(s), s[i]+s[j]);
        auto l = i + 1 + begin(s);
        ans += r - l;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3660
#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
deque<pair<double,double>> d1;
double totprod,totv;
int main(){
    double n,L;
    cin>>n>>L;
    for(double i=1;i<=n;i++){
        double t,v;
        cin>>t>>v;
        double tempv =v;
            double tempt =t;
        if(i>1){
            
            
            while(d1.size() && tempv){
                
                if(d1.front().second<=tempv){
                    
                    tempv-=(long double)1.0*d1.front().second;
                    totprod-=(long double)1.0*d1.front().first*d1.front().second;
                    totv-=d1.front().second;
                    d1.pop_front();
                }else{
                    totprod-=(long double)1.0*d1.front().first*d1.front().second;
                    d1.front().second-=tempv;
                    totprod+=(long double)1.0*d1.front().first*d1.front().second;
                   // cout<<123<<" "<<totprod<<endl;
                    //totv-=tempv;
                    tempv = 0;
                    break;
                }
            }
            
           // cout<<123<<" "<<totprod<<" "<<tempt*tempv<<endl;
         //   cout<<123<<" "<<totprod<<" "<<tempt*tempv<<" "<<d1.back().first<<endl;
        }
        
       // cout<<totprod<<endl;
       totprod+=(long double)1.0*v*t;
        cout<<setprecision(20)<<totprod/L<<endl;
       // cout<<tempv<<" "<<tempt<<endl;
      totprod-=(long double)1.0*v*t;
       tempv = v;
          //  cout<<1234<<" "<<v<<endl;
            while(d1.size() && d1.back().first>=tempt){
                totprod-=(long double)1.0*d1.back().first*d1.back().second;
                double tempp = (long double)1.0*tempv*tempt;
                tempp+=(long double)1.0*d1.back().first*d1.back().second;
               // cout<<123<<" "<<totprod<<endl;
                tempv+=d1.back().second;
                tempt = ((long double)1.0*tempp)/((long double)1.0*tempv);
                //cout<<1234<<" "<<tempt<<" "<<tempv<<endl;
                d1.pop_back();
            }
            totprod+=(long double)1.0*tempt*tempv;
        d1.push_back(make_pair(tempt,tempv));
    }
    
}


Measured memory_bytes: 19088
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		boolean[] color = new boolean[8];
		int n = sc.nextInt(), mi=0, ma=0;
		while (n-->0) {
			int a = sc.nextInt();
			if (a/400>7) ma++;
			else color[a/400]=true;
		}
		for (boolean t : color) if (t) mi++;
		// Missed the case where there could be ratings above 3200 only
		System.out.println(Math.max(mi,1)+" "+(mi+ma));
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 38964
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>


int main() {
    //std::ifstream in("in01.txt");
    //std::cin.rdbuf(in.rdbuf());

    int n;
    std::cin >> n;
    
    double ans, sum = 0;
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        sum += 1.0 / double(a);
    }
    ans = 1.0 / sum;
    std::cout << ans << std::endl;
    
    return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename FI,typename Compare>
pair<FI,FI> search_continuous(FI first,FI last,Compare comp){
	FI top = find_if(first,last,comp);
	if(top==last){
		return make_pair(last,last);
	}
	FI end = find_if_not(top,last,comp);
	return make_pair(top,end);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S=in<string>();
	int N=S.size();
	vector<char> SC(N);
	REP(i,N){
		SC[i]=S[i];
	}
	vector<int> A(N,0);

	auto begin = SC.begin(),end = SC.end();
	int index=0;
	while(begin!=end){
		auto R = search_continuous(begin,end,[](char ch){return ch=='R';});
		auto L = search_continuous(R.second,end,[](char ch){return ch=='L';});

		int RL = distance(R.first,R.second);
		int LL = distance(L.first,L.second);

		A[index+RL-1] = ((int)ceil(RL/2.0))+(LL/2);
		A[index+RL] = (RL/2)+((int)ceil(LL/2.0));

		index += RL+LL;
		begin = L.second;
	}

	PRINTALL(A);
	return 0;
}


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

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
 
	int k,n;
  cin>>k>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  vector<int> d(n);
  rep(i,n){
    if(v[i] <= v[(i+1)%n]) d[i] = v[i+1] - v[i];
    else {
      d[i] = (k - v[i]) + v[(i+1)%n];
    }
  }
  int min=k+1,sum=accumulate(d.begin(), d.end(), 0);
  sum -= *std::max_element(d.begin(), d.end());
  /*rep(i,n){
    if(sum-d[i]<min)min=sum;
  }*/
  cout<<sum;

  return 0;
}



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

int main() {
    string S;
    cin >> S;
    string Ans;

    if (S == "Sunny")
    {
        Ans = "Cloudy";
    }
    
    if (S == "Cloudy")
    {
        Ans = "Rainy";
    }
    
    if (S == "Rainy")
    {
        Ans = "Sunny";
    }
    
cout << Ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;
//using namespace atcoder;
struct LazySegmentTree{
private:
    ll n;
    vector<ll> node, lazy;
public:
    LazySegmentTree(vector<ll> v){
        ll sz=(ll)v.size();
        n=1;
        while(n<sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);
        rep(i,sz) node[i+n-1]=v[i];
        for(ll i=n-2;i>=0;i--) node[i]=max(node[2*i+1],node[2*i+2]);
    }
    void eval(ll k,ll l,ll r){
        if(lazy[k]!=0){
            node[k]+=lazy[k];
            if(r-l>1){
                lazy[2*k+1]=+lazy[k];
                lazy[2*k+2]=+lazy[k];
            }
            lazy[k]=0;
        }
    }
    void add(ll a,ll b,ll x,ll k=0,ll l=0,ll r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l || r<=a) return;
        if(a<=l && r<=b){
            lazy[k]+=(r-l)*x;
            eval(k,l,r);
        }
        else{
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=max(node[2*k+1],node[2*k+2]);
        }
    }
    ll getmax(ll a,ll b,ll k=0,ll l=0,ll r=-1){
        if(r<0) r=n;
        if(b<=l || r<=a) return 0;
        eval(k,l,r);
        if(a<=l && r<=b) return node[k];
        ll vl=getmax(a,b,2*k+1,l,(l+r)/2);
        ll vr=getmax(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
};

const ll mod=1e9+7;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n),dp(300001);
    rep(i,n){
        cin >> a[i];
    }
    LazySegmentTree seg=LazySegmentTree(dp);
    rep(i,n){
        ll l=max(0LL,a[i]-k);
        ll r=min(300000LL,a[i]+k)+1;
        ll val=seg.getmax(l,r);
        val++;
        ll v=seg.getmax(a[i],a[i]+1);
        seg.add(a[i],a[i]+1,val-v);
    }
    ll ans=0;
    rep(i,300001){
        ans=max(ans,seg.getmax(i,i+1));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 26764
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	int a, b, h; cin >> a >> b >> h;
	cout << (a + b)*h / 2 << endl;
	system("pause");
}

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

int main(){
  char s[57];
  char t[57];
  char *n;
  int ns,nt;
  int i,r,j;
  int flag[57];
  int sp = 0;
  int max = -999;

  scanf("%s %s", s, t);

  for(i = 0;i < 57;i++) flag[i] = 0;

  ns = strlen(s);
  nt = strlen(t);

  for(i = 0;i <= ns - nt;i++){
    r = 0;
      for(j = 0;j < nt;j++){
        if(t[r] == s[i + j] || s[i + j] == '?') r++;

        else break;

        if(r == nt){
          flag[sp] = i;
          sp++;
        }
      }
    }


  if(sp == 0) printf("UNRESTORABLE\n");

  else{
    n = s + flag[sp - 1];

    strncpy(n,t,nt);

    for(i = 0;i < ns;i++){
      if(s[i] == '?') s[i] = 'a';
    }

    printf("%s\n", s);
  }

  return 0;
}

Measured memory_bytes: 128
#include<iostream>  
#include<cstring>  
#include<cstdio>  
#include<cmath>  
#include<algorithm>  
  
using namespace std;  
  
bool s[15][10005]= {0};  
  
int n, m;  

void reverse(int row){
    for(int i=1; i<=m; i++){
        if(s[row][i]==0) s[row][i]=1;
        else s[row][i]=0;
    }
}

int dfs(int x)  
{  
    if(x==n+1)  
    {  
        int sum=0;  
        int term=0;  
        for(int j=1;j<=m;j++)  
        {  
            for(int i=1;i<=n;i++)  
                if(s[i][j]==1)term++;  
            //sum += term > n-term ? term : n-term;  
            term>n-term?(sum+=term):(sum+=(n-term));
            term=0;  
        }  
        return sum;  
    }  
    int a=dfs(x+1);  
    reverse(x);
    //for(int i=1;i<=m;i++)  
      //  s[x][i]=!s[x][i];  
    int b=dfs(x+1);  
    return a>b?a:b;
}  
  
int main()  
{  
    //freopen("in.in","r",stdin);  
    while(scanf("%d%d",&n,&m)!=EOF)  
    {  
        if(n==0&&m==0)break;   
        for(int i=1; i<=n; i++)  
            for(int j=1; j<=m; j++)  
                scanf("%d",&s[i][j]);  
        cout<<dfs(1)<<endl;  
    }  
    return 0;  
}  


Measured memory_bytes: 3224
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

int main(){
    long int n, T;
    cin >> n >> T;
    long int t[n];
    rep(i, n) cin >> t[i];
    long int ans = 0;
    long int dif = 0;

    rep(i, n - 1){
        ans += min(T, t[i+1] - t[i]);        
    }
    ans += T;
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>

const int INF = 1001001001;
const int mod = 1000000007;

int main() {
	long long a, b, c, d;
	std::cin >> a >> b >> c >> d;

	long long ans;
	ans = std::max(a*c,a*d);
	ans = std::max(ans, b * c);
	ans = std::max(ans, b * d);

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

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

#define MAX_N 100
#define MOD 1000000007

int n, dp[MAX_N + 1][4][4][4];

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

  dp[0][3][3][3] = 1;
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    for(int c1 = 0; c1 < 4; ++c1) {
      for(int c2 = 0; c2 < 4; ++c2) {
        for(int c3 = 0; c3 < 4; ++c3) {
          if(dp[i][c1][c2][c3] == 0) continue;

          for(int c4 = 0; c4 < 4; ++c4) {
            if(c2 == 0 and c3 == 1 and c4 == 2) continue;
            if(c2 == 0 and c3 == 2 and c4 == 1) continue;
            if(c2 == 1 and c3 == 0 and c4 == 2) continue;
            if(c1 == 0 and c3 == 1 and c4 == 2) continue;
            if(c1 == 0 and c2 == 1 and c4 == 2) continue;
            dp[i + 1][c2][c3][c4] += dp[i][c1][c2][c3];
            dp[i + 1][c2][c3][c4] %= MOD;
            if(i + 1 == n) {
              ans += dp[i][c1][c2][c3];
              ans %= MOD;
            }
          }
        }
      }
    }
  }

  std:: cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
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/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  ll n;
  cin>>n;
  vi p(n);
  rep(i,n) cin>>p[i];
  ll ans=0;
  rep(i,n){
    if(p[i]==i+1){
      ans++;
      if(i==n-1) continue;
      swap(p[i],p[i+1]);
    }
  }
  out(ans);
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int l;
  int sum=0,m=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>l;
    sum+=l;
    m=max(m,l);
  }
  sum-=m;
  if(m<sum){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main() {
	int n, d, i, j, k, num=0;
	double dis=0;
	cin >> n >> d;
	vector<vector<int>> X(n, vector<int>(d));
	for (i = 0; i < n; i++) {
		for (j = 0; j < d; j++) {
			cin >> X[i][j];
		}
	}
	for (i = 0; i < n; i++) {
		for (j = i+1; j < n; j++) {
			for (k = 0; k < d; k++) {
				dis += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
			}
			dis = sqrt(dis);
			if (ceil(dis) == floor(dis)) {
				num++;
			}
			dis = 0;
		}
	}
	cout << num << "\n";
	return 0;

}

Measured memory_bytes: 256
N = int(input())
S = input()

ans = 0
for i in range(1000):
    a, b, c = map(str, list(str(i).zfill(3)))
    mode = 'a'
    for j in S:
        if mode == 'a' and j == a:
            mode = 'b'
        elif mode == 'b' and j == b:
            mode = 'c'
        elif mode == 'c' and j == c:
            ans += 1
            break
print(ans)

Measured memory_bytes: 43932
#include <iostream>
using namespace std;
int main(){
    char key[8]="keyence";
    string str;
    int count=0;
    int halfpoint=0;
    bool miss=false;
    bool yes=false;
    cin >> str;

    if(str[0]!=key[0])miss=true;
    for(int i=0;i<str.length();i++){
        if(str[i]==key[count]){
            count++;
            if(count==7 && i==str.length()-1){
                cout << "YES";
                return 0;
            }
        }else if(count > 0){
            if(miss){count=0; continue;}
            halfpoint=count;
            for(int j=i;j<str.length();j++){ //途中まであっていた場合
                if(str[j]==key[count]){
                    count++;
                }else count=halfpoint;

                if(count==7 && j==str.length()-1){
                    cout << "YES";
                    return 0;
                }
            }
            count=0;
        }else count=0;
    }
    cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;
typedef std::vector< int > VI;

char rev(char a) {
  if (a == 'S') {
    return 'W';
  }
  return 'S';
}

int main(int argc, char* argv[])
{
  ll N;
  std::cin >> N;

  std::string s;
  std::string::iterator it;
  std::cin >> s;

  char a0[4] = { 'S', 'S', 'W', 'W' };
  char a1[4] = { 'S', 'W', 'S', 'W' };
  std::string sa(N, 'X');
  bool is_ok = false;

  for (int a = 0; a < 4; a++) {
    char last_animal;

    fill(sa.begin(), sa.end(), 'X');
    sa[0] = a0[a];
    sa[1] = a1[a];

    for (ll i = 1; i < N-1; i++) {
      if ((s[i] ==  'o' && sa[i] == 'S') || (s[i] == 'x' && sa[i] == 'W')) {
	sa[i+1] = sa[i-1];
      } else {
	sa[i+1] = rev(sa[i-1]);
      }
    }

    if ((s[0] ==  'o' && a0[a] == 'S') || (s[0] == 'x' && a0[a] == 'W')) {
      last_animal = a1[a];
      sa[1] = last_animal;
    } else {
      last_animal = rev(a1[a]);
      sa[1] = rev(last_animal);
    }

    if ((s[N-1] ==  'o' && last_animal == 'S') || (s[N-1] == 'x' && last_animal == 'W')) {
      sa[0] = sa[N-2];
    } else {
      sa[0] = rev(sa[N-2]);
    }

    if (sa[N-1] == last_animal && sa[0] == a0[a] && sa[1] == a1[a]) {
      is_ok = true;
      break;
    }
  }

  if (is_ok) {
    std::cout << sa << std::endl;
  } else {
    std::cout << -1 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 512
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int N[3];

	rep(i, 3)
		cin >> N[i];

	bool ans = false;

	if ((N[0] == N[1]) && N[0] != N[2])
		ans = true;

	if ((N[0] == N[2]) && N[0] != N[1])
		ans = true;

	if ((N[1] == N[2]) && N[0] != N[1])
		ans = true;

	if (ans)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

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

int main() {
  int n, x;
  cin >> n >> x;
  int mincost = 1001;
  for (int i=0; i<n; i++) {
    int c;
    cin >> c;
    x -= c;
    mincost = min(mincost, c);
  }
  cout << n + x/mincost << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;

int main() {
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int n, m, a[2000][2000] = {}, b, k, sum = 0, d=1, w, h,typ=0;
	long long dp[200005] = {}, memo[200005] = {};
	string str,str2;
	cin >> n;
	for (int i = 1; i < 2000; i++) {
		if (i * (i + 1) == 2 * n) {
			k = i;
			goto next;
		}
	}
	cout << "No";
	return 0;
next:
	cout << "Yes" << endl << k+1 << endl;
	for (int i = 1; i <= k; i++) {
		for (int j = i; j <= k; j++) {
			a[i][j] = d;
			d++;
		}
	}
	for (int i = 1; i <= k; i++) {
		int x = 1, y = i;
		d = 0;
		cout << k;
		while (d != k) {
			cout << " " << a[x][y];
			if (a[x + 1][y] == 0) { typ = 1; }
			if (typ == 0) { x++; }
			else { y++; }
			d++;
		}
		typ = 0;
		cout << endl;
	}
	cout << k;
	for (int i = 1; i <= k; i++) {
		cout <<" "<< a[i][i];
	}
}


Measured memory_bytes: 32640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;

int main()
{
	ll N;
	cin>>N;
	cout<<N+N*N+N*N*N<<endl;
}

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		atcode();
	}

	public static void atcode() {
		Scanner sc=new Scanner(System.in);
		String[] nx=sc.nextLine().split(" ");
		Integer n=Integer.valueOf(nx[0]);
		Integer x=Integer.valueOf(nx[1]);
		Integer min=1000;
		Integer count=0;
		for(int i=0;i<n;i++) {
			Integer m=Integer.valueOf(sc.nextLine());
			min=m.compareTo(min)<0?m:min;
			x-=m;
			count++;
		}
		count+=x/min;
		System.out.println(count);
	}
}


Measured memory_bytes: 21972
#include <stdio.h>

int main() {
        char s[3];
        scanf("%s", &s);
        int cal = 0;
        for (int i = 0; i < 3; i++) {
            if (s[i] == 'o') {
                cal += 100;
            }
        }
        printf("%d\n", cal + 700);
        return 0;
}


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

inline int F ( long long x )  {
	int sum ( 0 ) ;
	while ( x )  sum += x % 10, x /= 10 ;
	return sum ;
}

int main ( )  {
	long long N ;
	scanf ( "%lld", & N ) ;
	return ! puts ( N % F ( N ) ? "No" : "Yes" ) ;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
K = []
A = []
for i in range(N):
    tmp = list(map(int, input().split()))
    K.append(tmp[0])
    A.append(set(tmp[1:]))

res = A[0]
for i in range(1,N):
    res = res & A[i]

print(len(res))

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

int main(){
    string command;
    int k;
    priority_queue<int> S;
    while(cin >> command && command != "end"){
        if(command == "insert"){
            cin >> k;
            S.push(k);
        }else if(command == "extract"){
            cout << S.top() << endl;
            S.pop();
        }
    }
}

Measured memory_bytes: 7056
#include<stdio.h>
#include<string.h>

int main(void) {

	char i_str[1200];
	int i, len;
	fgets(i_str, 1200, stdin);
	len = strlen(i_str);
	for(i=0;i<len;i++) {
		if ((i_str[i] >= 'A') && (i_str[i] <= 'Z')) {
			printf("%c", i_str[i] + 0x20);
		} else if ((i_str[i] >= 'a') && (i_str[i] <= 'z')) {
			printf("%c", i_str[i] - 0x20);
		} else {
			printf("%c", i_str[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	
	int n; cin >> n;
	lli ans = 1;
	for (int i = 1; i <= n; i++){
		ans *= i;
		ans = ans % 1000000007;
	}

	cout << ans << endl;

	return 0;
}





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

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

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

  ll n, W; cin >> n >> W;
  vector<ll> w(110), v(110);
  rep(i, n) cin >> w[i] >> v[i] ;

  // dp[i][j] := i まで見た時に重さが j となる価値の最大値
  ll dp[110][100010] = {};
  rep(i, n) {
    for(int j = 0; j <= W; j++) {
      if(j-w[i] >= 0) {
        dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]]+v[i]);
      }
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
  }

  cout << dp[n][W] << '\n';
  return 0;
}


Measured memory_bytes: 86272
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
long long ans;
long long num[55],len[55];
long long  min(long long a,long long b){
	if(a>b)return b;
	return a;
}
long long dfs(long long n,long long x){
	if(n==0 && x==1)return 1;
	if(n>=0 && x==1)return 0;
	if(x==len[n])return num[n];
	long long aans=0;
	x--;
	aans+=dfs(n-1,min(x,len[n-1]));
	x=x-len[n-1];
	if(x<=0)return aans;
	x--;
	aans++;
	if(x<=0)return aans;
	aans+=dfs(n-1,min(len[n-1],x));
	return aans;
}
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	num[0]=1;
	len[0]=1;
	for(int i=1;i<=50;i++){
		num[i]=num[i-1]*2+1;
		len[i]=len[i-1]*2+3;
	}
	long long n,x;
	cin>>n>>x;
	ans=dfs(n,x);
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int f[10]={1,1,2,6,24,120,720,5040,40320};
int count(int x[],int n);
int take(int x[],int n);
int main()
{
    int a[8],b[8],n,x,y;

    scanf("%d",&n);

    take(a,n);
    take(b,n);

    x=count(a,n);
    y=count(b,n);

    if(x>y)
        printf("%d",x-y);
    else
        printf("%d",y-x);
}

int take(int x[],int n)
{
    int i;
    char d;
    for(i=0;i<n;i++)
        scanf("%d%c",&x[i],&d);
}

int count(int x[],int n)
{
    int i,s=0,j;
    for(i=0;i<n;i++)
    {
        s+=(f[n-i-1]*(x[i]-1));
        for(j=i+1;j<n;j++)
        {
            if(x[i]<x[j])
                x[j]-=1;
        }
    }
    return s;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(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 pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

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

    int H, W, A, B;
    cin >> H >> W >> A >> B;

    int num = 200010;
    vector<ll> fact(num), ifact(num);
    fact[0] = 1;
    fact[1] = 1;
    for (int i = 2; i < num; i++)
    {
        fact[i] = fact[i - 1] * i;
        fact[i] %= mod;
    }
    for (int i = 0; i < num; i++)
    {
        ifact[i] = modpow(fact[i], mod - 2);
        ifact[i] %= mod;
    }

    ll ans = 0;
    int c = 0;
    for (ll i = B+1; i <= W; i++) {
        ll h = H - A - 1;
        ll w = i - 1;
        ll tmp = fact[h+w] * ifact[h] % mod * ifact[w] % mod;
        h = A - 1; w = W - i;
        tmp *= fact[h+w] * ifact[h] % mod * ifact[w] % mod;
        ans += tmp % mod;
    }
    cout << ans % mod << endl;
    return 0;
}

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}

int main(){
  int n ,r;
  int ans = 0;
  cin >> n >> r;
  if(n < 10)ans = r + 100*(10-n);
  else ans = r;
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
ab = [[] for i in range(n+1)]

for i in range(m):
  a, b = map(int,input().split())
  ab[a].append(b)
  ab[b].append(a)

ans = [-1]*(n+1)
que = deque([1])

while que:
  q = que.popleft()
  for i in ab[q]:
    if ans[i] == -1:
      que.append(i)
      ans[i] = q

print("Yes")

for i in range(2,n+1):
  print(ans[i])

Measured memory_bytes: 33900
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll k,a,b;
    cin>>k>>a>>b;
    ll val=ceil(a/double(k));
    val=val*k;
    if(val>=a&&val<=b)
      cout<<"OK";
    else
      cout<<"NG";
}
return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  ll x[50],y[50];
  ll a[50],b[50];
  vi vec;
  cin >> n >> m;
  rep(i,0,n)cin >> x[i] >> y[i];
  rep(i,0,m)cin >> a[i] >> b[i];
  rep(i,0,n){
    ll ans = INF;
    rep(j,0,m){
      if(abs(x[i]-a[j])+abs(y[i]-b[j]) < ans){
        ans = abs(x[i]-a[j])+abs(y[i]-b[j]);
        l = j + 1;
      }
    }
    vec.pb(l);
  }
  rep(i,0,vec.sz)print(vec[i]);
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int prev = 0;
    for(int i=0;i<n;i++){
        int h;
        cin >> h;
        if(h == prev) continue;
        else if(h > prev) prev = h-1;
        else{
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    
    return 0;
}

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

namespace codeTester.contest190707
{
    class ProblemB
    {
        static List<long> nd = new List<long>();
        static List<List<long>> values = new List<List<long>>();
        static int answer = 0;

        public static void Main(string[] args)
        {
            Input();
            Logic();
            Output();
        }

        static void Input()
        {
            nd = ReadSpaceSeparatedValues();
            values = ReadSpaceSeparatedLists((int)nd[0]);
        }

        public static List<List<long>> ReadSpaceSeparatedLists(int n)
        {
            List<List<long>> returnValue = new List<List<long>>();
            for (int i = 0; i < n; i++)
            {
                returnValue.Add(ReadSpaceSeparatedValues());
            }
            return returnValue;
        }

        public static List<long> ReadSpaceSeparatedValues()
        {
            List<long> values = new List<long>();
            string[] inputs = Console.ReadLine().Split(' ');
            foreach (string input in inputs)
            {
                values.Add(long.Parse(input));
            }

            return values;
        }

        static void Logic()
        {
            int squareDistanceCount = 0;
            int n = (int)nd[0];
            int d = (int)nd[1];
            for (int i = 0; i < n; i++)
            {
                for(int j = i+1; j < n; j++)
                {
                    long squaredDistance = values[i]
                        .Zip(values[j], (iValue, jValue) => iValue - jValue)
                        .Aggregate((long)0, (sum, next) => sum + (next * next));

                    DebugPrint(squaredDistance.ToString());
                    if (isSquareNumber(squaredDistance))
                    {
                        squareDistanceCount++;
                    }
                }
            }
            answer = squareDistanceCount;
        }

        static bool isSquareNumber(long value)
        {
            if (value == Math.Pow((int)Math.Sqrt(value), 2))
            {
                DebugPrint("O");
                return true;
            }
            DebugPrint("X");
            return false;
        }

        static void Output()
        {
            Console.WriteLine(answer.ToString());
        }

        static void DebugPrint(string msg)
        {
            // 提出時に消す
            // Console.WriteLine(msg);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

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

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    vector<bool> yes(n + 1, 0);
    for(int i = 0; i < n + 1; i += 4)
    {
        for(int j = 0; j < n + 1; j += 7) yes[i + j] = 1;
    }
    if(yes[n]) cout << "Yes";
    else cout << "No";

    return 0;
}


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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define f first
#define s second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll INF = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int inf = (int)1e9;

const int N = 300500;

ll ng, mg, n, m;
string s, t;
map <ll, char> c;

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	cin >> n >> m >> s >> t;

	ll k = n * m / __gcd(n, m);
	ng = n / __gcd(n, m);
	mg = m / __gcd(n, m);

	for(ll j = 0; j < n; ++j)
		c[j * mg] = s[j];
	for(ll j = 0; j < m; ++j)
		c[j * ng] = t[j];	
	
	for(ll j = 0; j < n; ++j)
		if(c[j * mg] != s[j]){
			cout << -1;
			return 0;
		}
	for(ll j = 0; j < m; ++j)
		if(c[j * ng] != t[j]){
			cout << -1;
			return 0;
		}

	cout << k;

	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}

Measured memory_bytes: 10880
import math
N,M = map(int,input().split())
A = list(map(int,input().split()))
a = sum(A)
b = math.ceil(a/(4*M))
cnt = 0
for i in range(N):
    if A[i]>=b:
        cnt += 1
if cnt>=M:
    print("Yes")
else:
    print("No")

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
	ll n;cin>>n;
	vector<int> a(n);
	ll i,j;
	rep(i,n)cin>>a[i];
	vector<pair<ll,ll>> p(n);
	rep(i,n)p[i]=make_pair(a[i],i);
	sort(all(p));
	reverse(all(p));
	vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
	rep(i,n+1)
	{
		rep(j,n+1-i)
		{
			if(i==0&&j==0)continue;
			if(i==0)
			{
				dp[i][j]=dp[i][j-1]+p[i+j-1].first*abs(n-j-p[i+j-1].second);
			}
			else if(j==0)
			{
				dp[i][j]=dp[i-1][j]+p[i+j-1].first*abs(p[i+j-1].second+1-i);
			}
			else dp[i][j]=max(dp[i-1][j]+p[i+j-1].first*abs(p[i+j-1].second+1-i),dp[i][j-1]+p[i+j-1].first*abs(n-j-p[i+j-1].second));
		}
	}
	ll ans=0;
	rep(i,n+1)ans=max(ans,dp[i][n-i]);
	cout<<ans<<endl;
}


Measured memory_bytes: 34648
import math
n, m = map(int, input().split())
ans = 0
if n-m == 0:
    ans = math.factorial(n)*math.factorial(m)*2
elif n-m == 1 or n-m == -1:
    ans = math.factorial(n)*math.factorial(m)

print(int(ans%(1000000000+7)))


Measured memory_bytes: 55152
U = 2*10**6
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
  fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U],MOD-2,MOD)
 
for i in range(U,0,-1):
  fact_inv[i-1] = (fact_inv[i]*i)%MOD
 
def comb(n,k):
  if k < 0 or k > n:
    return 0
  z = fact[n]
  z *= fact_inv[k]
  z %= MOD
  z *= fact_inv[n-k]
  z %= MOD
  return z

n, k = map(int, input().split())
l = k-1
A = sorted(list(map(int, input().split())))
m, M= 0, 0
for i in range(n-l):
  c = comb(n-1-i, l)
  m += A[i]*c
  m %= MOD
  M += A[n-1-i]*c
  M %= MOD
print((M-m)%MOD)

Measured memory_bytes: 96348
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=((t)-1);i>=s;--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define mcpy(des,sor) memcpy(des,sor,sizeof(sor))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define fi first
#define se second
#define sq(x) ((x)*(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
 
const int inf = 0x3f3f3f3f;
const ll mod = 1e9+7;
const db eps = 1e-8;
 
 
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,a,ff,fb,bf,bb;ll t,s1,s2;vector<int> A;deque<int> q,p;
	cin>>n;
	rep(i,0,n)
	{
		cin>>a;
		A.pb(a);
	}
	s1=s2=0;
	sort(all(A));for(auto a:A)q.pb(a);
#define ft front()
#define bk back()
#define pf push_front
#define pft pop_front
#define pbk pop_back
	p.pb(q.ft);q.pft();
	while(sz(q))
	{
		ff=abs(q.ft-p.ft);
		fb=abs(q.ft-p.bk);
		bf=abs(q.bk-p.ft);
		bb=abs(q.bk-p.bk);
		t=max(max(ff,fb),max(bf,bb));s1+=t;
		if(t==ff)p.pf(q.ft),q.pft();
		else if(t==fb)p.pb(q.ft),q.pft();
		else if(t==bf)p.pf(q.bk),q.pbk();
		else if(t==bb)p.pb(q.bk),q.pbk();
	}
	
	while(sz(p))p.pbk();
	sort(all(A));for(auto a:A)q.pb(a);
	p.pb(q.bk);q.pbk();
	while(sz(q))
	{
		ff=abs(q.ft-p.ft);
		fb=abs(q.ft-p.bk);
		bf=abs(q.bk-p.ft);
		bb=abs(q.bk-p.bk);
		t=max(max(ff,fb),max(bf,bb));s2+=t;
		if(t==ff)p.pf(q.ft),q.pft();
		else if(t==fb)p.pb(q.ft),q.pft();
		else if(t==bf)p.pf(q.bk),q.pbk();
		else if(t==bb)p.pb(q.bk),q.pbk();
	}
 
	
	cout<<max(s1,s2)<<endl;
}

Measured memory_bytes: 1144