akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int p[100];

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

	int N; cin >> N;
	for (int i = 1; i <= N; i++) cin >> p[i];

	bool ans = false;

	for (int i = 1; i <= N; i++) {
		for (int j = i; j <= N; j++) {

			int q[100];
			for (int k = 1; k <= N; k++) q[k] = p[k];
			swap(q[i], q[j]);

			bool flag = true;
			for (int i = 1; i <= N - 1; i++) {
				if (q[i] > q[i + 1]) flag = false; // 昇順になっていなかったら
			}

			if (flag) ans = true;
		}
	}

	if (ans) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

using namespace std;

int main() {

    int N, K;
    cin >> N >> K;

    double p = 0;

    double m = 0;

    for (int i = 1; i <= K; i *= 2) {
        m += 1;
    }

    for (int i = 1; i <= N; i++) {

        double pi = 1;

        int n = i;

        while (n <= K - 1) {
            n *= 2;
            pi *= 2;
        }

        p += ((double) 1) / pi;
    }

    p = p * ((double) 1 / (double) N);

    cout << fixed << setprecision(11) << p << "\n";

    return 0;

}

Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

typedef modint<MOD> m;
m func[400001];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
m comb(m n, m r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 0;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}

int main() {
	int arr[3][3];
	bool flag[3][3];
	rep(i, 3) {
		rep(j, 3) {
			cin >> arr[i][j];
			flag[i][j] = false;
		}
	}

	cin >> N;
	rep(k, N) {
		cin >> B;
		rep(i, 3) {
			rep(j, 3) {
				if (arr[i][j] == B) {
					flag[i][j] = true;
				}
			}
		}
	}

	rep(i, 3) {
		bool f = true;
		rep(j, 3) {
			f &= flag[i][j];
		}
		if (f) {
			cout << "Yes";
			return 0;
		}
	}

	rep(i, 3) {
		bool f = true;
		rep(j, 3) {
			f &= flag[j][i];
		}
		if (f) {
			cout << "Yes";
			return 0;
		}
	}

	bool f = true;
	rep(i, 3) {
		f &= flag[i][i];
	}
	if (f) {
		cout << "Yes";
		return 0;
	}

	f = true;
	rep(i, 3) {
		f &= flag[i][2 - i];
	}
	if (f) {
		cout << "Yes";
		return 0;
	}

	cout << "No";
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
D = list(map(int,input().split()))

counts = Counter(D)
Dmax = max(D)

flg = True
if D[0] != 0:
    flg = False
if counts[0] != 1:
    flg = False

if flg:
    ans = 1
    for i in range(1,Dmax+1):
        ans *= counts[i-1]**counts[i]
        ans %= 998244353
else:
    ans = 0

print(ans)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

signed main(){
    string S; int Q;
    cin >> S >> Q;
    bool is_inverse = false;
    deque<char> q;
    rep(i,S.length()){
        q.push_back(S[i]);
    }
    rep(query,Q){
        int type = 0;
        cin >> type;
        if(type==1){
            is_inverse = !is_inverse;
        }else{
            char c;
            cin >> type >> c;
            if(type==1){
                if(is_inverse){
                    q.push_back(c);
                }else{
                    q.push_front(c);
                }
            }else{
                if(is_inverse){
                    q.push_front(c);
                }else{
                    q.push_back(c);
                }
            }
        }
    }
    while(!q.empty()){
        if(!is_inverse){
            cout << q.front();
            q.pop_front();
        }else{
            cout << q.back();
            q.pop_back();
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

//ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
	if (b) { ll d = euclid(b, a % b, y, x);
		return y -= a/b * x, d; }
	return x = 1, y = 0, a;
}
const ll MOD=1e9+7;
ll inv(ll a) {
    ll x, y;
    euclid(a,MOD,x,y);
    return (x+MOD)%MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    const int M=3*n;
    vector<ll> fact(M);
    fact[0]=1;
    rep(i,1,M) {
        fact[i]=(i*fact[i-1])%MOD;
    }

    vector<ll> a(n);
    int mink=(n+1)/2;
    rep(k,mink,n) {
        int holes=n-1-k;
        int j=k-1-holes;
        a[k]=fact[k];//((holes+2)*fact[k-1])%MOD;
        a[k]=(a[k]*fact[j+holes])%MOD;
        a[k]=(a[k]*inv(fact[j]))%MOD;
        //a[k]=(a[k]*inv(fact[holes]))%MOD;
        //debug(a[k]);
    }
    ll ans=0;
    rep(k,mink,n) {
        ll x=(a[k]-a[k-1]+MOD)%MOD;
        x=(x*k)%MOD;
        ans=(ans+x)%MOD;
    }
    cout<<ans<<"\n";
}


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

int main(){

  string s; cin>>s;

  int count =0;

  for(int i=0; i<s.size(); i++){
    for(int j=0; j<s.size(); j++){

      if(i == j) continue;

      if(s.at(i) == s.at(j)) count++;
    }

  }

  if(count > 0) cout<<"no"<<endl;

  else if(count == 0) cout<<"yes"<<endl;

  return 0;

  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
	string s;
	cin >> s;
	int np = (int)count(s.begin(), s.end(), '+');
	int nm = (int)count(s.begin(), s.end(), '-');
	cout << np - nm << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class T, class F>
T UpperBound(T i0, T i1, F f) {
    while (i0 < i1) {
        T i = i0 + (i1 - i0) / 2;
        if (f(i)) i0 = i + 1; else i1 = i;
    }
    return i0;
}

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

    for (int _ = 0; _ < q; _++) {
        ll a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);

        ll r = 0;
        if (a < b) {
            ll c = a * b;
            auto i = UpperBound<ll>(a, b, [&](auto i) {
                return i * i < c;
            });

            r = (i - a) * 2;
            r -= (i - 1) * i >= c;
            r -= r > 0;
        }
        r += (a - 1) * 2;

        cout << r << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
s=list(input())
t=list(input())
r=tn=len(t)
for u in (s[i:i+tn] for i in range(len(s)-tn+1)):
	k=0
	for i,j in zip(u,t):
		k+=(i!=j)
	r=min(r,k)
print(r)

Measured memory_bytes: 8980
#include <iostream>

#include <algorithm> // std::min
#include <limits> // std::numeric_limits
#include <map> // std::map
#include <utility> // std::pair, std::make_pair
#include <vector> // std::vector

using ll = long long;

template <class AdjacencyMatrix, class Distance>
Distance traveling_salesman_from(AdjacencyMatrix &a, size_t start) {
    size_t n = a.size();
    std::vector<std::vector<Distance>> dp(1 << n, std::vector<Distance>(n, std::numeric_limits<Distance>::infinity()));

    for (size_t goal = 0; goal < n; ++goal) {
        dp[0][goal] = a.distance(start, goal);
    }

    for (int b = 1; b < (1 << n); ++b) {
        for (size_t goal = 0; goal < n; ++goal) {
            if (b & (1 << goal)) {
                continue;
            }
            for (size_t v = 0; v < n; ++v) {
                if (v == start || v == goal || (b & (1 << v)) == 0) {
                    continue;
                }
                dp[b][goal] = std::min(dp[b][goal], dp[b ^ (1 << v)][v] + a.distance(v, goal));
            }
        }
    }
    return dp[((1 << n) - 1) ^ (1 << start)][start];
}

class adjacency_matrix {
private:
    const size_t n;
    std::map<std::pair<size_t, size_t>, double> m;
public:
    adjacency_matrix (size_t n) : n(n) { }
    void make_edge(size_t from, size_t to, double weight) {
        m[std::make_pair(from, to)] = weight;
    }
    size_t size() const {
        return n;
    }
    double distance(size_t from, size_t to) {
        auto e = std::make_pair(from, to);
        if (m.count(e)) {
            return m[e];
        } else if (from == to) {
            return 0.0;
        } else {
            return std::numeric_limits<double>::infinity();
        }
    }
};

int main() {
    int V, E;
    std::cin >> V >> E;
    adjacency_matrix a(V);
    for (int i = 0; i < E; ++i) {
        int s, t, d;
        std::cin >> s >> t >> d;
        a.make_edge(s, t, d);
    }
    double result = traveling_salesman_from<adjacency_matrix, double>(a, 0);
    if (result == std::numeric_limits<double>::infinity()) {
        result = -1;
    }
    std::cout << result << std::endl;
    return 0;
}


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

int waruni(int x){
  int sum=0;
  while(x%2==0){
    x=x/2;
    sum++;
  }
  return sum;
}
int main(){
  int n;
  cin>>n;
  
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=waruni(a.at(i));
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

struct test{
  int team_name,answers;
};

int main(){
  while(1){
    int m,t,p,r;
    cin>>m>>t>>p>>r;
//    cout<<en
    if(m==t&&t==p&&p==r&&r==0) break;
    test teams[55];
    int mistake[55][11]={0};
    int times[55]={0};
    for(int i=0; i<55; i++){
      teams[i].answers=0;
      times[i]=0;
    }
    vector<P> ve;
    for(int i=0; i<r; i++){
      int time,team,id,judge;
      cin>>time>>team>>id>>judge;
      if(judge) mistake[team][id]++;
      else{
        teams[team].answers++;
        times[team]+=mistake[team][id]*20+time;
      }
    }
    
    for(int i=1; i<=t; i++){
      ve.push_back(mk(teams[i].answers,i));
//      cout<<"   i = "<<i;
//      cout<<"          ans = "<<teams[i].answers<<en
    }
//
//    cout<<en
    
    sort(ve.begin(), ve.end(), greater<P>());
//    for(auto v=0; v<ve.size(); v++){
//      cout<<ve[v].second<<"  time:  "<<times[ve[v].second]<<en
//    }
//    cout<<en
//    cout<<en
    
    for(int v=1; v<ve.size(); v++){
      P now=ve[v];
      int j=v-1;
      while(j>=0&&ve[j].first==now.first&&times[now.second]<times[ve[j].second]){
        ve[j+1]=ve[j];
        j--;
      }
      ve[j+1]=now;
    }
    
    for(int i=0; i<ve.size(); i++){
      cout<<ve[i].second;
      if(i==ve.size()-1) break;
      if(ve[i].first==ve[i+1].first&&times[ve[i].second]==times[ve[i+1].second]) cout<<'=';
      else cout<<',';
    }
    cout<<en
  }
  RE
}


Measured memory_bytes: 3088
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=2000+10,mo=924844033;
int f[maxn][maxn][4],g[maxn],h[maxn],fac[maxn];
int i,j,k,l,r,t,n,m,ans;
int main(){
	scanf("%d%d",&n,&k);
	fac[0]=1;
	fo(i,1,n) fac[i]=(ll)fac[i-1]*i%mo;
	f[1][0][0]=1;
	f[1][1][2]=1;
	fo(i,1,n-1)
		fo(j,0,i)
			fo(t,0,3)
				if (f[i][j][t]){
					(f[i+1][j][(t>>1)]+=f[i][j][t])%=mo;
					if (t%2==0) (f[i+1][j+1][(t>>1)]+=f[i][j][t])%=mo;
					(f[i+1][j+1][(t>>1)+2]+=f[i][j][t])%=mo;
				}
	g[0]=1;
	fo(r,1,k){
		t=r;
		l=1;
		while (t+k<=n){
			l++;
			t+=k;
		}
		fo(i,0,n) h[i]=0;
		fo(i,0,n)
			fo(j,0,l)
				fo(t,0,1)
					if (i+j<=n) (h[i+j]+=(ll)g[i]*f[l][j][t]%mo)%=mo;
		fo(i,0,n) g[i]=h[i];
	}
	fo(i,0,n){
		t=(ll)g[i]*fac[n-i]%mo;
		if (i%2) (ans-=t)%=mo;else (ans+=t)%=mo;
	}
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 61312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int n,a[maxn];

int main(){
	cin >> n;
	for(int i=1; i<=n; i++){
		int x = read(); x++;
		a[x]++;
		a[x-1]++;
		a[x+1]++;
	}
	int ans = 0;
	for(int i=1; i<maxn; i++)
		ans = max(ans,a[i]);
	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
long long n,l[1200];
int main()
{
cin>>n;
l[0]=2;l[1]=1;
for(int i=2;i<=n;i++)
{
l[i]=l[i-1]+l[i-2];
}
cout<<l[n]<<endl;
return 0;
}

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

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

  int A[n];
  for(int i = 0; i < n; i++){
    cin >> A[i];
  }

  int num = 0;
  for(int i =0 ; i < n; i++){
    int minj = i;
    for(int j = i; j <n; j++) {
      if(A[j] < A[minj]) {
        minj = j;
      }
    }
    if(minj != i) {
        swap(A[i],A[minj]);
        num++;
      }
  }

  for(int i = 0; i < n; i++) {
    if(i) cout << " ";
    cout << A[i];
  }

  cout << endl;
  cout << num << endl;
}


Measured memory_bytes: 3108
#include <iostream>
using namespace std;
int main(){
int a,b,c,min;
cin>>a>>b>>c;
min=a;
if(b<min) min=b;
if(c<min) min=c;

if(min==a){
if(b<c)   cout<<a<<" "<<b<<" "<<c<<endl;
else      cout<<a<<" "<<c<<" "<<b<<endl;
}
else if(min==b){
if(a<c)    cout<<b<<" "<<a<<" "<<c<<endl;
else       cout<<b<<" "<<c<<" "<<a<<endl;
}
else if(min==c){
if(a<b)     cout<<c<<" "<<a<<" "<<b<<endl;
else        cout<<c<<" "<<b<<" "<<a<<endl;
}
}

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(string, S);
  
  int ct = 0;
  for(int i=0; i<S.size() / 2; ++i) {
    int r = S.size() - i - 1;
    
    if(S[i] != S[r]) ct++;
  }
  
  fin(ct);
}

Measured memory_bytes: 256
#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 ss = s.size()-1;
  int n = (ss/2) + 1;
  int ans=0;
  rep(i, n){
    if(s.at(i) != s.at(ss)) ans++;
    ss--;
  }

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

Measured memory_bytes: 256
N=int(input())
ps=[]
tp=[]
ap=[]
for i in range(N):
  p=input().split()
  ps.append([int(p[0])+int(p[1]),i])
  tp.append(int(p[0]))
  ap.append(int(p[1]))
    
def is_even(num):
  if num % 2 == 0:
    return True
  else:
    return False

T=0
A=0
calc=sorted(ps,reverse=True)
#print(calc)
i=0
for p,j in calc:
  if is_even(i):
    T+=tp[j]
  else:
    A+=ap[j]
  i+=1
print(T-A)


Measured memory_bytes: 28752
#include<bits/stdc++.h>
using namespace std;
long long n,k,p[5050],c[5050],ret=-1e18-1e9;
bool vis[5050];
vector<long long>v;
list<long long>q;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
		p[i]--;
	}
	for(int i=0;i<n;i++)
	{
		cin>>c[i];
		ret=max(ret,c[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(vis[i])
		{
			continue;
		}
		int x=p[i];
		vis[i]=true;
		v.clear();
		v.push_back(0);
		v.push_back(c[p[i]]);
		long long summ=c[p[i]];
		while(!vis[x])
		{
			vis[x]=true;
			x=p[x];
			summ+=c[x];
			v.push_back(c[x]);
		}
		long long nw=k,ans=0;
		bool ok=false;
		if(summ>0)
		{
			int vvv=v.size()-1;
			if(nw/vvv-1>0)
			{
				ok=true;
			}
			ans+=max(((nw/vvv)-1),0ll)*summ;
			if(nw>vvv)
			{
				nw%=vvv;
				nw+=vvv;
			}
		}
//		cout<<ans<<endl;
		int nwn=v.size();
		for(int j=1;j<nwn;j++)
		{
			v.push_back(v[j]);
		}
		for(int j=1;j<nwn;j++)
		{
			v.push_back(v[j]);
		}
		for(int j=2;j<v.size();j++)
		{
			v[j]+=v[j-1];
		}
//		for(int j=1;j<v.size();j++)
//		{
//			cout<<v[j]<<' ';
//		}
//		cout<<endl;
		long long mx=-1e18-1e9;
		while(!q.empty())
		{
			q.pop_back();
		}
		q.push_front(0);
		for(int j=1;j<v.size();j++)
		{
			while(!q.empty() && v[q.front()]>v[j])
			{
				q.pop_front();
			}
			q.push_front(j);
			while(!q.empty() && j-q.back()>nw)
			{
				q.pop_back();
			}
			if(j!=q.back())
			{
				mx=max(mx,v[j]-v[q.back()]);
			}
//			cout<<mx<<' ';
		}
		ans+=mx;
		ret=max(ret,ans);
	}
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 3892
// https://atcoder.jp/contests/abc102/tasks/arc100_a

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

ll N, A[200000], t, med, c;

int main()
{
  c = 0;
  cin >> N;
  REP(i, N)
  {
    cin >> t;
    A[i] = t - i - 1;
  }

  sort(A, A + N);
  med = N % 2 ? A[(N - 1) / 2] : (A[N / 2 - 1] + A[N / 2]) / 2;

  REP(i, N)
  {
    c += abs(A[i] - med);
  }

  cout << c << '\n';

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int idoukyori;
  int boll;
  for(int i = 0;i<N;i++){
    cin >> boll;
    idoukyori += min(boll*2,(K-boll)*2);
  } 
  cout << idoukyori << endl;
}

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

typedef pair<int, int> P;

int main(void) {
    int N;
    cin >> N;
    int cx = 0;
    int cy = 0;
    int ct = 0;
    REP(i, N) {
        int t, x, y;
        cin >> t >> x >> y;
        int d = (t-ct) - abs(x-cx) - abs(y-cy);
        if(d < 0 || d%2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
DP = [float('inf')] * N
DP[0] = 0
DP[1] = abs(H[1] - H[0])
for i in range(2, N):
    DP[i] = min(DP[i - 1] + abs(H[i] - H[i - 1]), DP[i - 2] + abs(H[i] - H[i - 2]))
print(DP[N - 1])

Measured memory_bytes: 13980
#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, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int cnt = 0;
    rep(i, n){
        if(h[i] >= k){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
#define pb push_back
using namespace std;

typedef pair<int,int> P;

int main(){
  int n,m,p,q,r;
  int x[10000],y[10000];
  vector<P> v,tmp;

  while(cin >> n, n){
    cin >> m >> p >> q >> r;
    for(int i=0;i<m;i++)cin >> x[i] >> y[i];
    
    v.clear();
    v.pb(P(p,q));
    
    for(int i=m-1;i>=0;i--){
      tmp.clear();
      for(int j=0;j<(int)v.size();j++){
	int b = v[j].first, e = v[j].second;
	if(e<=n-y[i])tmp.pb(P(b + y[i], e + y[i]));
	else if(b<=n-y[i]){
	  if(e<=n-x[i]){
	    tmp.pb(P(b + y[i],n));
	    tmp.pb(P(x[i]+1,x[i] + e - (n-y[i]) ));
	  }else{ 
	    tmp.pb(P(b + y[i],n));
	    tmp.pb(P(x[i]+1,y[i]));
	    tmp.pb(P(1,e - (n-x[i])));
	  }
	}
	else if(e<=n-x[i])tmp.pb(P(b - (n-y[i]) + x[i],e - (n-y[i]) + x[i]) );
	else if(b<=n-x[i]){
	  tmp.pb(P(b - (n-y[i]) + x[i],y[i]));
	  tmp.pb(P(1,e - (n-x[i])));
	}
	else tmp.pb(P(b - (n-x[i]),e - (n-x[i])));
      }
 
      v = tmp;
    }
    
    int ans = 0;
    for(int i=0;i<(int)v.size();i++){
      if(v[i].second<=r)ans += v[i].second - v[i].first + 1;
      else if(v[i].first<=r)ans += r - v[i].first + 1;
    }
    cout << ans <<endl;
  }
}

Measured memory_bytes: 1076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static int InsertionSort(final int N, final int G, int[] A){
		int cnt = 0;
		//System.out.println("> " + G);
		for(int i = G; i < N; i++){
			final int v = A[i];
			int j = i - G;
			//System.out.println(i + " " + j);
			while(j >= 0 && A[j] > v){
				A[j + G] = A[j];
				j -= G;
				cnt++;
			}
			
			A[j + G] = v;
		}
		
		return cnt;
	}
	
	public static void ShellSort(final int N, int[] A){
		int cnt = 0;
		int m = 1;
		int[] G = new int[100];
		G[0] = 1;
		for(int i = 1; i < N; i++, m++){
			G[i] = G[i - 1] * 3 + 1;
			if(G[i] > N){
				break;
			}
		}
		
		for(int i = 0; i < m; i++){
			cnt += InsertionSort(N, G[m - i - 1], A);
		}
		
		System.out.println(m);
		for(int i = m - 1; i >= 0; i--){
			if(i != m - 1){
				System.out.print(" ");
			}
			System.out.print(G[i]);
		}
		System.out.println();
		System.out.println(cnt);
		for(int i = 0; i < N; i++){
			System.out.println(A[i]);
		}	
	}
	
	public static void main(String args[]) {
		//Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		try{
			final int N = Integer.parseInt(br.readLine());
			int[] A = new int[N];
		
			for(int i = 0; i < N; i++){
				A[i] = Integer.parseInt(br.readLine());
			}
		
			ShellSort(N, A);
			
		}catch(IOException e){
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 100596
def foo(xs, n):
    largest = - 10**6
    smallest = 10**6
    largest_i = -1
    smallest_i = -1
    for i, x in enumerate(xs):
        if largest < x:
            largest = x
            largest_i = i
        if smallest > x:
            smallest = x
            smallest_i = i

    ys = []
    if smallest < 0 and abs(smallest) > largest:
        for i in range(n-2, -1, -1):
            while xs[i+1] < xs[i]:
                xs[i] += smallest
                ys.append((smallest_i, i))
                if xs[i] < smallest:
                    smallest_i = i
                    smallest = xs[i]
    else:
        for i in range(1, n):
            while xs[i-1] > xs[i]:
                xs[i] += largest
                ys.append((largest_i, i))
                if xs[i] > largest:
                    largest_i = i
                    largest = xs[i]
    return ys



if __name__ == "__main__":
    n = int(input())
    xs = list(map(int, input().split()))
    ys = foo(xs, n)
    print(len(ys))
    for i, j in ys:
        print("%d %d"%(i+1, j+1))

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main (void){
	int X, ans, root, i;
	int flag =0; /*判定フラグ*/
	scanf("%d", &X);
	
	while(1){
		root = (int)sqrt(X);
		
		for (i =2; i<root; ++i){
			if(X%i==0){
				flag =1;
				break;
			}
		}
		
		if (flag == 0){
			ans = X;
			break;
		}
		flag =0;
		X +=1;
	}
	
	printf("%d", ans);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = n;
    for(int i = 0; i <= n; i++) {
      int j = n - i;
      int s = i;
      int t = j;
      int p = 0;
      while(s > 0) {
        p += (s % 6);
        s /= 6;
      }
      while(t > 0) {
        p += (t % 9);
        t /= 9;         
      }
      ans = Math.min(ans, p);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;
typedef long long ll;

int main(){
	ll X;
	cin>>X;
	ll ans=0;
	while(X>=500){
		ans+=1000;
		X-=500;
	}
	while(X>=5){
		ans+=5;
		X-=5;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
s = input()
n = int(input())
for i in range(n):
    l = input().split()
    if l[0] == 'replace':
        s = s[:int(l[1])] + str(l[3]) + s[int(l[2]) + 1:]
    elif l[0] == 'reverse':
        s = s[:int(l[1])] + s[int(l[1]):int(l[2])+1][::-1] + s[int(l[2]) + 1:]
    elif l[0] == 'print':
        print(s[int(l[1]):int(l[2]) + 1])



Measured memory_bytes: 5616
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <cmath>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

static const int MAX = 100001;

/******* c++14 don't include *******/

template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }

/*******                      *******/

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int n, q;
    string s;
    cin >> n >> q;
    cin >> s;
    int dp[MAX];
    fill(dp, dp+MAX, 0);
    rep(i, n-1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            dp[i] = 1;
        }
        if(i)dp[i] += dp[i-1];
    }
    
    rep(i, q){
        int l, r;
        cin >> l >> r;
        l--; r--;
        int sum = 0;
        int left = 0;
        if(l)left = dp[l-1];
        sum = dp[r-1]-left;
        cout << sum << endl;
    }

    return 0;
}



Measured memory_bytes: 1408
#include <stdio.h>
int a[1000005];
int main()
{
	int N, T;
	scanf("%d%d", &N, &T);
	for(int i = 1; i <= N; i++){
		scanf("%d", &a[i]);
	}
	int sum = T;
	for(int i = 2; i <= N; i++){
		int h = a[i] - a[i -1];
		if(h >= T) sum += T;
		else sum += h;
	}
	printf("%d", sum);
	return 0;
}


Measured memory_bytes: 896
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define efo(i,v,u) for(int i=BB[v],u=B[BB[v]][1];i;u=B[i=B[i][0]][1])
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std;
typedef long long ll;typedef double db;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0'||'9'<ch;ch=getchar())if(ch=='-')p=-1;for(;'0'<=ch && ch<='9';ch=getchar())n=n*10+ch-'0';return n*p;}
const int N=8e5+5,mo=924844033;
void inc(ll &x,ll y){x=(x+y)%mo;}
ll qmi(ll x,ll n)
{
	ll t=1;
	for(x%=mo;n;n>>=1,x=x*x%mo) if(n&1) t=t*x%mo;
	return t;
}
int n,B0,BB[N],B[N][2];
void link(int u,int v){B[++B0][1]=v,B[B0][0]=BB[u],BB[u]=B0;}
ll ans[N],fac[N],iv[N],f[N],g[N];
int size[N];
void dfs(int v,int fr=0)
{
	size[v]=1;
	efo(i,v,u) if(u!=fr)
	{
		dfs(u,v);
		size[v]+=size[u];
	}
	if(size[v]!=n) ++f[size[v]],++f[n-size[v]];
}
int len,lg,bitrev[N];
ll invlen,W[N];
void dft(ll *a,int sig=1)
{
	fo(i,0,len-1) if(i<bitrev[i]) swap(a[i],a[bitrev[i]]);
	for(int i=2,gap=len>>1;i<=len;i<<=1,gap>>=1)	
		for(int j=0;j<len;j+=i)
			for(ll k=0,*l=a+j,*r=a+j+(i>>1),*w=sig>0?W:W+len;k<(i>>1);++k,++l,++r,w=sig>0?w+gap:w-gap)
			{
				ll u=*l,v=*r * *w%mo;
				*l=(u+v)%mo,*r=(u-v+mo)%mo;
			}
	if(sig==-1) fo(i,0,len-1) a[i]=a[i]*invlen%mo;
}
void ntt(ll *c,ll *a,ll *b)
{
	for(len=1,lg=0;len<=n+n;len<<=1,++lg);
	invlen=qmi(len,mo-2);
	W[0]=1,W[1]=qmi(5,(mo-1)/len);
	fo(i,2,len) W[i]=W[i-1]*W[1]%mo;
	fo(i,0,len-1) bitrev[i]=(bitrev[i>>1]>>1)|((i&1)<<(lg-1));
	dft(a);
	dft(b);
	fo(i,0,len-1) c[i]=a[i]*b[i];
	dft(c,-1);
}
int main()
{
	int x,y;
	n=read();
	fac[0]=iv[0]=1;
	fo(i,1,n) fac[i]=fac[i-1]*i%mo;
	iv[n]=qmi(fac[n],mo-2);
	fd(i,n-1,1) iv[i]=iv[i+1]*(i+1)%mo;
	fo(i,1,n-1) x=read(),y=read(),link(x,y),link(y,x);
	dfs(1);
	fo(i,0,n) f[i]=f[i]*fac[i]%mo,g[i]=iv[i];
	reverse(f+1,f+n+1);
	ntt(ans,f,g);
	reverse(ans+1,ans+n+1);
	fo(i,1,n) ans[i]=ans[i]*iv[i]%mo;
	fo(i,1,n) ans[i]=(n*fac[n]%mo*iv[i]%mo*iv[n-i]%mo-ans[i]+mo)%mo;
	fo(i,1,n) printf("%lld\n",ans[i]);
	return 0;
}

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

int main(){
  int N, S = 0, n;
  cin >> N;
  n = N;

  while( n > 0){
    S += n % 10;
    n /= 10; 
  }
  if( N % S == 0)  cout << "Yes" << endl;
  else  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	cout << n * n << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int a[10];

int cost(int i, int j) {
	return abs(a[i] - a[j]);
}

int main() {
	cin >> a[1] >> a[2] >> a[0];
	a[3] = a[0]; a[6] = a[0];
	a[4] = a[1]; a[7] = a[1];
	a[5] = a[2]; a[8] = a[2];
	int ans = 1000000;
	for (int i = 0; i < 3; i++) {
		int temp = 0;
		temp += min(cost(i, i + 1) + cost(i + 1, i + 2), cost(i, i + 2) + cost(i + 1, i + 2));
		ans = min(ans, temp);
	}

	print(ans);





	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {

	static int lowerbound(int[] A, int key) {
		int high = A.length;
		int low = -1;
		while(high - low > 1) {
			int mid = (low + high)/2;
			if(A[mid] >= key) {
				high = mid;
			} else {
				low = mid;
			}
		}
		return high;
	}

	static int upperbound(int[] A, int key) {
		int high = A.length;
		int low = -1;
		while(high - low > 1) {
			int mid = (low + high)/2;
			if(A[mid] > key) {
				high = mid;
			} else {
				low = mid;
			}
		}
		return high;
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] A = new int[n];
		for(int i=0; i<n; i++){
			A[i] = sc.nextInt();
		};

		int[] B = new int[n];
		for(int i=0; i<n; i++){
			B[i] = sc.nextInt();
		};

		int[] C = new int[n];
		for(int i=0; i<n; i++){
			C[i] = sc.nextInt();
		};
		sc.close();

		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);

		long count = 0;
		for(int i=0; i<n; i++){
			int x = lowerbound(A, B[i]);
			int y = n - upperbound(C, B[i]);
			count += (long) x * y;
		};
		System.out.println(count);
	}
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        int ans=0;
        rep(i,6)
        {
                char c; cin>>c;
                ans+=c-'0';
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<int> a, b;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,q;
    cin >> n >> k >> q;
    vector<ll> count(n, 0);
    rep(i, q)
    {
        ll temp;
        cin >> temp;
        temp--;
        count[temp]++;
    }
    rep(i, n)
    {
        if (k - q + count[i]<=0)no;
        else yes;
    }
}


Measured memory_bytes: 1408
# d : 隣接行列
# n : n * n
def warshall_floyd(n, d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
                #print(d)
    return d
h, w = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(h)]
c = warshall_floyd(10, c)
import collections
dic = collections.defaultdict(int)
for i in range(h):
    for j in range(w):
        dic[a[i][j]] += 1
ans = 0
for key in dic.keys():
    if key != -1:
        ans += c[key][1] * dic[key]
print(ans)

Measured memory_bytes: 3700
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string s; cin >> s;
	if (s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	x, _ := sc.NextInt()
	n, _ := sc.NextInt()
	p, _ := sc.NextInts(n)
	ans := solve(x, n, p)
	fmt.Println(ans)
}

func solve(x, n int, p []int) int {
	sort.Slice(p, func(i, j int) bool { return p[i] < p[j] })
	for i := 0; ; i++ {
		if !contains(p, x-i) {
			return x - i
		} else if !contains(p, x+i) {
			return x + i
		}
	}
}

func contains(p []int, v int) bool {
	n := len(p)
	i := sort.Search(n, func(i int) bool { return p[i] >= v })
	return i < n && p[i] == v
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}

// NextInts reads n integers from io stream.
func (sc *Scanner) NextInts(n int) (arr []int, e error) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		v, e := sc.NextInt()
		if e != nil {
			return nil, e
		}
		arr[i] = v
	}
	return arr, nil
}


Measured memory_bytes: 1760
#include <stdio.h>

char island[12][13];
int island_number[12][12];

void union_find(int i, int j)
{	
	if (i >= 0 && i + 1 <= 11 && j >= 0 && j <= 11){
		if (island[i + 1][j] == '1' && island_number[i][j] != island_number[i + 1][j]){
			island_number[i + 1][j] = island_number[i][j];
			union_find(i + 1, j);
		}
	}
		
	if (i - 1 >= 0 && i <= 11 && j >= 0 && j <= 11){
		if (island[i - 1][j] == '1' && island_number[i][j] != island_number[i - 1][j]){
			island_number[i - 1][j] = island_number[i][j];
			union_find(i - 1, j);
		}
	}

	if (i >= 0 && i <= 11 && j >= 0 && j + 1 <= 11){
		if (island[i][j + 1] == '1' && island_number[i][j] != island_number[i][j + 1]){
			island_number[i][j + 1] = island_number[i][j];
			union_find(i, j + 1);
		}
	}

	if (i >= 0 && i <= 11 && j - 1 >= 0 && j <= 11){
		if (island[i][j - 1] == '1' && island_number[i][j] != island_number[i][j - 1]){
			island_number[i][j - 1] = island_number[i][j];
			union_find(i, j - 1);
		}
	}

}

int main(void)
{
	int i, j, num[12 * 12], cnt;
	
	while (scanf("%s", island[0]) != EOF){		
		for (i = 1; i < 12; i++){
			scanf("%s", island[i]);
		}
		
		for (i = 0; i < 12; i++){
			for (j = 0; j < 12; j++){
				island_number[i][j] = i * 12 + j + 1;
				num[i * 12 + j] = 0;
			}
		}
		
		for (i = 0; i < 12; i++){
			for (j = 0; j < 12; j++){
				if (island[i][j] == '1'){
					union_find(i, j);
				}
				else {
					island_number[i][j] = 0;
				}
			}
		}
		
		for (i = 0; i < 12; i++){
			for (j = 0; j < 12; j++){
				if (island_number[i][j] > 0){
					num[island_number[i][j] - 1] = 1;
				}
			}
		}
		
		for (i = 0, cnt = 0; i < 12 * 12; i++){
			if (num[i] == 1){
				cnt++;
			}
		}
		
		printf("%d\n", cnt);
	}
	
	return (0);
}

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

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

using ll = long long;
using ull = unsigned long long;

int main() {
  int n, m;
  cin >> n >> m;
  int a[n][m];
  int b[m];
  rep(i, n) rep(j, m) cin >> a[i][j];
  rep(i, m) cin >> b[i];
  int ans = 0;
  rep(i, n) {
    rep(j, m) {
      ans += a[i][j] * b[j];
    }
    cout << ans << endl;
    ans = 0;
  } 
  return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int a[510][510],H,W,h,w;
int main()
{
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if (!(H%h)&&!(W%w)) return puts("No"),0;
	puts("Yes");
	a[0][0]=(H/h)*(W/w)+1;
	a[h-1][w-1]=-a[0][0]-1;
	for (int i=0;i<H;i++,puts(""))
	for (int j=0;j<W;j++)
		printf("%d ",a[i%h][j%w]);
	return 0;
}

Measured memory_bytes: 2048
r, l = map(int, input().split())
ans = 2018
for i in range(r,l):
    for j in range(r+1,l+1):
        if ans > (i*j) % 2019:
            ans = (i*j) % 2019
            if ans == 0:
                break

    if ans == 0:
        break

print(ans)


Measured memory_bytes: 9084
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String string = sc.next();

    String first = string.substring(0, 2);
    String second = string.substring(2, 4);
    boolean f = isMonth(first);
    boolean s = isMonth(second);
    
    String ans = null;
    if (f && !s) {
      ans = "MMYY";
    } else if (!f && s) {
      ans = "YYMM";
    } else if (f && s){
      ans = "AMBIGUOUS";
    } else {
      ans = "NA";
    }
    
    System.out.println(ans);
  }
  
  private static boolean isMonth(String string) {
    String[] month = {
      "01", "02", "03", "04", "05", "06", 
      "07", "08", "09", "10", "11", "12"
    };
    for (int i = 0; i < month.length; i++) {
      if (month[i].equals(string)) {
        return true;
      }
    }
    return false;
  }
}

Measured memory_bytes: 21844
import java.util.Scanner;

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

        String S = sc.next();
        int cnt = 0, diff = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'S') {
                diff++;
            } else if (S.charAt(i) == 'T') {
                diff--;
                if (diff < 0) {
                    cnt++;
                    diff = 0;
                }
            }
        }
        System.out.println(cnt + diff);
    }
}


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

int main() {
  
  int S;
  cin>>S;
  
  int a=S/100;
  int b=S%100;

  if (a>12 && b>12) {
    cout << "NA" <<endl;
  }
  
  else if (a<=12 && b<=12) {
    if (a>=1 && b>=1) {
      cout <<"AMBIGUOUS"<<endl;
    }
    else if (a>=1 && b==0) {
      cout << "MMYY"<<endl;
    }
    else if (a==0 && b>=1) {
      cout <<"YYMM"<<endl;
    }
    else if (a==0 && b==0) {
      cout<<"NA"<<endl;
    }
  }
  
  else if (a>12 && b<=12) {
    if (b==0) {
      cout<<"NA"<<endl;
    }
    else {
      cout<<"YYMM"<<endl;
    }
  }
  else if (a<=12 && b>12) {
    if (a==0) {
      cout<<"NA"<<endl;
    }
    else {
      cout<<"MMYY" <<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int l=s.length();
    int ans=0;
    for(int i=1;i<=l;++i) {
        if(s[i]==s[i-1]) {
            if(s[i]=='0') s[i]='1';
            else s[i]='0';
            ++ans;
        }
        
    }
    cout << ans << endl;
}


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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}



int main()
{
    ll N,K,d;
    cin >> N >> K;

    ll A[N+1];

    rep(i,N){
        cin >> d;
        A[i+1]=d;
    }

    ll path[200002],T=1,temp=1,did[200002];

    rep(i,200002){
        did[i]=0;
        path[i]=-1;
    }

    path[0]=1;
    did[1]=1;

    while(1){
        if(did[A[temp]]==1){
            break;
        }
        temp=A[temp];
        path[T]=temp;
        T++;
        did[temp]=1;
    }

    ll itr=0,first;

    while(1){
        if(path[itr]==A[temp]){
            first=itr;
            break;
        }
        itr++;
    }

    if(K<=first){
        cout << path[K];
        return 0;
    }

    K=K-first;
    T=T-first;

    ll ans = (K%T)+first;

        cout << path[ans] << endl;

 
    return 0;

}

Measured memory_bytes: 8308
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll n;
    cin >> n;
    ll ans = 0;
    ll i = 10;
    if (n % 2 == 0) {
        while(n >= i) {
            ans += n / i;
            i *= 5;
        }
    } 

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256