akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	int wsk = 1;
	ll pocz = 100, x;
	cin >> x;
	int cnt = 0;
	while (pocz < x) {
		pocz = (ll) pocz * 1.01;
		++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3656
#include<iostream>

using std::cout;
using std::cin;
using std::endl;

int main(){
    int N, D;
    cin >> N >> D;
    int result;
    int count = N;
    int edge = 0;
    result = (((D + 1) * 2) - 1);
    while(1){
        count -= result;
        ++ edge;
        if(count <= 0) break;
    }
    cout << edge;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    string s;
    cin>>s;
    int n = s.length();
    string now = "";
    string prev = "";
    prev += s[0];
    int cnt = 1;
    for(int i=1;i<n;i++)
    {
        now += s[i];
        if( now != prev )
        {
            prev = now;
            now = "";
            cnt++;
        }
    }
    cout<<cnt,nl;

    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;
using T = tuple<int,char,int>; //p,d,i

int main(){
    int n,l;
    while(cin>>n>>l,n){
        int R[l+1],L[l+1];
        fill(R,R+l+1,0);
        fill(L,L+l+1,0);

        for(int i=1;i<=n;i++){
            char d;
            int p;
            cin>>d>>p;
            // cout<<d<<' '<<p<<' '<<i<<endl;
            if(d=='R'){
                R[p]=i;
            }else{
                L[p]=i;
            }
        }
        int cnt = n;
        int last = -1;
        int t=0;
        while(cnt){
            t++;
            if(R[l]){
                last=R[l];
                R[l]=0;
                cnt--;
            }
            if(L[0]){
                last=L[0];
                L[0]=0;
                cnt--;
            }
            for(int loc=1;loc<l;loc++){
                if(L[loc]){
                    L[loc-1]=L[loc];
                    L[loc]=0;
                }
            }
            for(int loc=l-1;loc>0;loc--){
                if(R[loc]){
                    R[loc+1]=R[loc];
                    R[loc]=0;
                }
            }
            for(int loc=1;loc<l;loc++){
                if(R[loc]&&L[loc]) swap(R[loc],L[loc]);
            }
        }
        cout<<t-1<<' '<<last<<endl;
    }

    return 0;
}

Measured memory_bytes: 2968
if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    b = 1

    if a[0]<= 0 and a[1]>=0:
        b=0
    elif a[1]<0:
        c = abs(a[0]-a[1])
        if c %2 ==0:
            b=-1


    if b >0:
        print("Positive")
    elif b ==0:
        print("Zero")
    else:
        print("Negative")

Measured memory_bytes: 38256
x,y=map(int,input().split())
ans=abs(abs(x)-abs(y))
if y==0:
    if x>0:
        ans+=1
elif x>=0:
    if y<0:
        ans+=1
    elif x>y:
        ans+=2
else:
    if y>0:
        ans+=1
    elif x>y:
        ans+=2

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s,s!="#"){
		int y,m,d;
		cin>>y>>m>>d;
		bool heisei=!(y>31||(y==31&&m>4));
		if(!heisei){
			y-=30;
		}
		puta((heisei?s:"?"),y,m,d);
	}
}



Measured memory_bytes: 3216
x=[i for i in input()]
count=0

if len(x)%2!=0:
  x.pop(len(x)//2)

P =[p for p in range(0,len(x)//2)]
Q =[q for q in range(len(x)//2,len(x))]
Q.sort(reverse=True)
for a,b in zip(P,Q):
  if x[a]!=x[b]:
    count+=1
print(count)
  

Measured memory_bytes: 3060
N = int(input())
outputStr = ""
while(N):
    if(N % 2 == 1):
        outputStr = "1" + outputStr
        N = (N - 1) / (-2)
    else:
        outputStr = "0" + outputStr
        N = N / (-2)
if(outputStr == ""):
    print(0)
else:
    print(outputStr)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
int main(void)
{
    int N;cin>>N;
    int id;
    vector<ll> h;

    for(int i=0;i<N;i++){
      ll hh; cin>>hh; h.push_back(hh);
    }
    if(N==1){
      cout<<"Yes"<<endl; return 0;
    }
    for(int i=0;i<N-1;i++){
      if(h[i]<h[i+1]) h[i+1]--;

      if(h[i]>h[i+1]){
        cout<<"No"<<endl; return 0;
      }
    }

   cout<<"Yes"<<endl;


    return 0;
}


Measured memory_bytes: 1400
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
C = 0

for i in T:
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == i:
            C += 1
            break
        elif S[mid] < i:
            left = mid + 1 
        else:
            right = mid
print(C)

Measured memory_bytes: 18992
k, s = gets.split.map(&:to_i)
cnt = 0
f = [s - k * 2, 0].max
f.upto(k) do |x|
  f.upto(k) do |y|
    cnt += 1 if 0 <= s - x - y && s - x - y <= k
  end
end
p cnt

Measured memory_bytes: 1916
N = int(input())
A = list(map(int, input().split()))
X = []
for i in range(N):
    X.append(sum(A) - 2 * sum([x for j, x in enumerate(A) if j % 2 != 0]) if i == 0 else 2 * A[i-1] - X[i-1])
print(' '.join(list(map(str, X))).strip())


Measured memory_bytes: 76388
r,g,b,n = map(int,input().split())

ans = 0
for i in range(n+1):
    for j in range(n+1):
        tmp = (r*i)+(g*j)
        if tmp > n:
            break
        else:
            if (n-tmp)%b == 0:
                ans += 1

print(ans)

Measured memory_bytes: 67480
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

int n, si[20005], pre[20005], nxt[20005];
char a[20005], b[20005];
vector<pii> pi;

int s(int x){
	if (x == -1) return 0;
	return si[x];
}

int sum(int l, int r){
	if (l <= r) return s(r) - s(l - 1);
	return s(r) + s(n - 1) - s(l - 1);
}

void gen(){
	n = 2000;
	srand(clock());
	REP(i, 0, n - 1){
		a[i] = rand() % 2 + '0';
		b[i] = rand() % 2 + '0';
	}
	a[n] = b[n] = '\0';
}

int main(){
	// freopen("d.in", "r", stdin);
	scanf("%s%s", a, b);
	if (strcmp(a, b) == 0){
		return puts("0"), 0;
	}
	n = strlen(a);
	// gen();
	// puts(a);
	// puts(b);
	REP(i, 0, n - 1){
		si[i] = b[i] - '0';
		if (i) si[i] += si[i - 1];
	}
	pre[0] = -1;
	PER(i, n - 1, 0) if (b[i] == '1'){
		pre[0] = i; break;
	}
	if (b[0] == '1') pre[0] = 0;
	if (pre[0] == -1) return puts("-1"), 0;

	REP(i, 1, n - 1){
		if (b[i] == '1') pre[i] = i;
		else pre[i] = pre[i - 1];
	}

	nxt[n - 1] = 0;
	REP(i, 0, n - 1) if (b[i] == '1'){
		nxt[n - 1] = i; break;
	}
	if (b[n - 1] == '1') nxt[n - 1] = n - 1;
	PER(i, n - 2, 0)
		nxt[i] = b[i] == '1' ? i : nxt[i + 1];
	// REP(i, 0, n - 1){
	// 	debug("pre[%d] = %d\n", i, pre[i]);
	// 	debug("nxt[%d] = %d\n", i, nxt[i]);
	// }

	int ans = n * n;
	REP(dx, - n + 1, 0){
		int dy = 0;
		int cnt = 0;
		pi.clear();
		REP(i, 0, n - 1){
			int pos = (i + dx + n) % n;
			if (a[i] == b[pos]) continue;
			++cnt;
			if (sum(pos, i)) continue;
			pi.pb(mp((pos - pre[pos] + n) % n, (nxt[i] - i + n) % n));
			// dy = max(dy, (nxt[i] - i + n) % n);
		}
		sort(pi.begin(), pi.end(), greater<pii>());
		dy = 233333;
		int asd = 0;
		RVC(i, pi){
			pii x = pi[i];
			dy = min(dy, asd + x.fi);
			asd = max(asd, x.se);
		} dy = min(dy, asd);
		// cerr << cnt << endl;
		ans = min(ans, dy * 2 + abs(dx) + cnt);
	}
	REP(dx, 0, n - 1){
		int dy = 0, cnt = 0;
		pi.clear();
		REP(i, 0, n - 1){
			int pos = (i + dx) % n;
			if (a[i] == b[pos]) continue;
			++cnt;
			if (sum(i, pos)) continue;
			pi.pb(mp((i - pre[i] + n) % n, (nxt[pos] - pos + n) % n));
		}
		sort(pi.begin(), pi.end(), greater<pii>());
		dy = 233333;
		int asd = 0;
		RVC(i, pi){
			pii x = pi[i];
			dy = min(dy, asd + x.fi);
			asd = max(asd, x.se);
		} dy = min(dy, asd);
		// cerr << cnt << endl;
		ans = min(ans, dy * 2 + dx + cnt);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()
    lst = [False]*8
    god = 0
    for i in a:
        rank = i//400
        if rank<=7:
            lst[rank] = True
        else:
            god += 1
    ans = lst.count(True)
    if ans == 0:
        ans = 1
        god -= 1

    print(ans,ans + god)

main()

Measured memory_bytes: 74572
import sys


# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

# ===CODE===
def main():
    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    n,q = map(int,input().split())
    que = UnionFind(n)

    for _ in range(q):
        com, x, y = map(int, input().split())
        if com:
            if que.same(x,y):
                print(1)
            else:
                print(0)
        else:
            que.union(x,y)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5804
#pragma region // {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
#pragma endregion // }}}


void main() {
    int n,k;
    R(n,k);
    VI a(n), b(n);
    REP(i,n) R(a[i],b[i]);
    k++;
    LL ans=0;
    // int cant=0;
    for ( int t=30; ~t; t-- ) {
        LL cur=0;
        // if ( k>>t&1 ) {
        //     cant^=(1<<t);
        //     REP(i,n) if ( (cant&a[i])==0 ) cur+=b[i];
        //     cant^=(1<<t);
        // } else {
        //     cant^=(1<<t);
        // }
        if ( k>>t&1 ) {
            int me=k^(1<<t);
            me|=(1<<t)-1;
            REP(i,n) if ( (me&a[i])==a[i] ) cur+=b[i];
            chmax(ans,cur);
        }
    }
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}


Measured memory_bytes: 4072
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;
typedef pair<string, string> pss;

int main()
{
	int n,m;
	cin >> n;
	map<ll, int> mp;


	rep(i, n) {
		ll d;
		cin >> d;
		mp[d]++;
	}

	cin >> m;
	vector<ll> t(m);
	rep(i, m)cin >> t[i];

	rep(i,m) {
		if (mp[t[i]] == 0) {
			cout << "NO" << endl;
			return 0;
		}else{
			mp[t[i]]--;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 16384
#include <iostream>
#include <string>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);(i)++)
using namespace std;

int main()
{
  int A,B;
  cin >> A >> B;

  // 開始時間
  int C;
  C = (A + B) % 24;
  cout << C << endl;

  return 0;
}


Measured memory_bytes: 256
#import <stdio.h>
#import <stdlib.h>
typedef long long INT;
int main(){
    INT N;
    scanf("%lld",&N);
    INT *S = (INT*)malloc((N+1)*sizeof(INT));
    S[0] = 0;
    INT sign = 1;
    for(INT i=1;i<=N;i++){
        INT a;
        scanf("%lld",&a);
        S[i] = S[i-1] + sign * a;
        sign *= -1;
    }
    sign = 1;
    for(INT i=1;i<=N;i++){
        printf("%lld", sign * (S[N]-2*S[i-1]));
        sign *= -1;
        if(i<N) printf(" ");
    }
}


Measured memory_bytes: 7120
#include<stdio.h>
#include<stdlib.h>

static int compareInt(const void* a, const void* b)
{
    int aNum = *(int*)a;
    int bNum = *(int*)b;

    return aNum - bNum;
}

int main(void)
{
  int n, m, sum=0;
  
  scanf("%d %d", &n, &m);
  
  int i1, x[m], d[m-1];
  
  for(i1=0;i1<m;i1++) scanf("%d", &x[i1]);
  qsort(x, m, sizeof(int), compareInt);
  
  for(i1=0;i1<m-1;i1++) d[i1]=x[i1+1]-x[i1]; 
  qsort(d, m-1, sizeof(int), compareInt);
  
  for(i1=0; i1<m-n;i1++) sum+=d[i1];
  
  printf("%d", sum);
  
  return 0;
}

Measured memory_bytes: 1396
def kaibun(S):
  for i in range(len(S)//2):
    if S[i] != S[-i-1]:
      return 0
  return 1

S = input()
length = int((len(S)-3)/2)
frag1 = kaibun(S)
test = [0]*int((len(S)-1)/2)
for i in range(length+1):
  test[i] = S[i]
frag2 = kaibun(test)
for i in range(length+1):
  test[i] = S[i+int((len(S)+1)/2)]
frag3 = kaibun(test)
if frag1 == 1 and frag2 == 1 and frag3 == 1:
  print('Yes')
else:
  print('No')

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

using namespace std;

const int N = 100100;

int col[N];
int tru[N];
int cnt = 1;


int main(){
    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%d", &col[i]);
    }
    int mn = *min_element(col,col+n);
    int mx = *max_element(col,col+n);

    //printf("%d %d\n", mn, mx);

    if(mx-mn>1){
        puts("No");
    }
    else if(mx-mn == 1){
    	int x = 0;
    	int y = 0;
        for(int i = 0; i < n; i++){
            if(mn == col[i]){
                x++;
            }
            else{
            	y++;
            }
        }
        if(x+1<=mx&&mx<=x+y/2){
        	puts("Yes");
        }
        else{
        	puts("No");
        }
        
    }
    else{
        if(mn<=n/2||mn==n-1){
        	puts("Yes");
        }
        else{
            puts("No");
        }
        
    }

   
    
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, N, M) for (int i = N; i < M; i++)
#define pb push_back



typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int , int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef priority_queue<pll, vector<pll>, greater<pll>> greater_pq;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>

void f(string& str) {
	str.insert(str.begin(), str.back());
	str.pop_back();
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> a(M), b(M), color(M, 0);
	vector<pii > v;
	vector<pii > w;

	rep(i, M) {
		cin >> a[i] >> b[i];
		--a[i];
		--b[i];
		v.push_back(make_pair(i, a[i]));
		w.push_back(make_pair(i, b[i]));
	}

	sort(all(v), [](pii x, pii y) {return x.second<y.second; });
	sort(all(w), [](pii x, pii y) {return x.second<y.second; });
	ll res = 0;
	ll state = 0;
	ll j = 0;
	rep(i, M) {
		if (color[w[i].first] == 1) {
			continue;
		}
		res++;
		for (j=state; j<M; j++) {
			if (v[j].second < w[i].second) {
				color[v[state].first] = 1;
				state++;
			}
		}


	}

	cout << res << endl;

	return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
vector<pair<pair<ll,ll>,ll> >v;
vector<pair<ll,pair<int,int> > >edg;
ll ans;
int sz[N],arr[N];
void init(){
	for(int i=0;i<N;i++){
		sz[i]=1;
		arr[i]=i;
	}
	return ;
}
int root(int a){
	if(arr[a]!=a){
		return arr[a]=root(arr[a]);
	}else{
		return a;
	}
}
void un(int a,int b,ll cost){
	int root_a=root(a),root_b=root(b);
	if(root_a==root_b){
		return ;
	}else{
		ans+=cost;
		if(sz[root_a]>=sz[root_b]){
			sz[root_a]+=sz[root_b];
			arr[root_b]=root_a;
		}else{
			sz[root_b]+=sz[root_a];
			arr[root_a]=root_b;
		}
	}
	return;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	init();
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		ll a,b;cin>>a>>b;
		v.push_back({{a,b},i});
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n-1;i++){
		edg.push_back({v[i+1].first.first-v[i].first.first,{v[i].second,v[i+1].second}});
		edg.push_back({v[i+1].first.first-v[i].first.first,{v[i+1].second,v[i].second}});
	}
	for(int i=0;i<v.size();i++){
		swap(v[i].first.first,v[i].first.second);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n-1;i++){
		edg.push_back({v[i+1].first.first-v[i].first.first,{v[i].second,v[i+1].second}});
		edg.push_back({v[i+1].first.first-v[i].first.first,{v[i+1].second,v[i].second}});
	}
	sort(edg.begin(),edg.end());
	for(auto u:edg){
		un(u.second.first,u.second.second,u.first);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 15596
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let s = get_line();
    let mut result = String::new();
    for c in s.chars() {
        if !c.is_alphabetic() {
            result.push(c);
            continue;
        }
        if c.is_lowercase() {
            result += &c.to_uppercase().to_string();
        } else {
            result += &c.to_lowercase().to_string();
        }
    }

    println!("{}", result);
}



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

int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    a*=100;
    b*=100;
    int maxs,maxw;
    double ma;
    for(int i=0;a*i<f;i++){
        for(int j=0;a*i+j*b<f;j++){
            for(int k=0;a*i+b*j+k*d<f;k++){
                for(int l=0;a*i+b*j+c*k+l*c<f;l++){
                    int wa=a*i+b*j;
                    int sh=c*k+d*l;
                    if(wa==0 || sh==0)continue;
                    if(wa+sh>f)break;
                    if(sh*100>e*wa)break;
                    if(ma*(wa+sh)<100*sh){
                        ma=(double)100*sh/(wa+sh);
                        maxw=wa+sh;
                        maxs=sh;
                    }
                }
            }
        }
    }
    if(maxw==0 && maxs==0)maxw=a;
    cout << maxw << " " << maxs << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;


void solve(){
    int r;
    cin>>r;
    cout<<r*r<<endl;
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	//cout<<fixed<<setprecision(15);
	solve();
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, d, a;
    cin >> n >> d >> a;
    vll x(n), h(n), s(2 * n, -1);
    vll vx;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> h[i];
        h[i] = h[i] / a + (h[i] % a > 0);
        vx.push_back(x[i]);
        vx.push_back(x[i] + 2LL * d);
    }
    sort(all(vx));
    vx.erase(unique(all(vx)), vx.end());
    for (int i = 0; i < n; i++) {
        int to = lower_bound(all(vx), x[i]) - vx.begin();
        s[to] = h[i];
    }
    ll sum = 0, res = 0;
    queue<P> q;
    for (int i = 0; i < vx.size(); i++) {
        if (s[i] != -1) {
            ll t = max(0LL, s[i] - sum);
            sum += t;
            res += t;
            q.push(P(vx[i], t));
        }
        while (!q.empty()) {
            if (q.front().first + 2LL * d == vx[i]) {
                sum -= q.front().second;
                q.pop();
            } else {
                break;
            }
        }
    }
    cout << res << endl;
}


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

int main() {
  int N; long long M; cin >> N >> M;
  int a[100010],b[100010]; long long bkt[100010]={0};
  for(int i = 0; i < N; i++) {
  cin >> a[i] >> b[i];
  }
  for(int i = 0; i < N; i++) {
  bkt[a[i]]+=b[i];
  }
  for(int ans = 1;ans <= 100010;ans++){
    if(M <= bkt[ans]){
      cout << ans << endl;
      break;
    } 
    M -= bkt[ans];
  }

  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=2e3+10;
int N;
vector<pair<ll,int>>A;
ll dp[MAXN][MAXN];
bool cmp(pair<ll,int>p1,pair<ll,int>p2)
{
    return p1.first>p2.first;
}
void solve()
{
    cin>>N;
    for(int u=1;u<=N;u++){
        ll t;
        cin>>t;
        A.push_back({t,u});
    }
    sort(A.begin(),A.end(),cmp);
    for(int u=1;u<=N;u++){
        for(int t=0;t<u;t++){
            int l=t;
            int r=u-1-l;
            ll v=A[u-1].first,p=A[u-1].second;
            dp[l+1][r]=max(dp[l+1][r],dp[l][r]+v*abs(l+1-p));
            dp[l][r+1]=max(dp[l][r+1],dp[l][r]+v*abs(N-r-p));
        }
    }
    ll ans=0;
    for(int v=0;v<=N;v++){
        ans=max(ans,dp[v][N-v]);
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 26300
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

factmod=[0 for i in range(100000)]
factmod[0]=1
for i in range(100000-1):
    factmod[i+1]=factmod[i]*(i+2)%mod
n,m=MI()
if n>m+1 or m>n+1:
    print(0)
    sys.exit()
elif n==m:
    ans=2*factorial(n)**2
else:
    if m>n:
        m,n=n,m
    ans=factorial(n)*factorial(m)
print(ans%mod)

Measured memory_bytes: 55860
#include <bits/stdc++.h>
        #define endl '\n'
        #define modulo 1000000007
        #define int long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643383279502884
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        #define f first
       // #define s second
        using namespace std;
        int power(int x,int y,int m)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2,m))%m;
        if (y%2 == 0)
        return ((temp%m)*temp);
        else
        return ((x*temp%m)*temp%m)%m;
        }
        int inv(int x)
        {
        return (power(x,modulo-2,modulo))%modulo;
        }
        bool comp(int a,int b)
        {
            return a>b;
        }
        ///Solution created by:Ahmadsm2005
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input0.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            int n,X,buff,counter=0;
            cin>>n>>X;
            for(int i=0;i<n;i++){
            cin>>buff;
            if(counter+buff>X){
            cout<<i+1;
            exit(0);
            }
            counter+=buff;
            }
            cout<<n+1;
            return 0;
        }


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

using namespace std;
typedef long long ll;
 
int main(){
  ll N;
  cin >> N;
  vector<vector<ll>> a(21,vector<ll>(21,0));
  vector<ll> A(N);

  for(int i=0;i<N;i++){
    string str;
    cin >> str;
    double d;
    d=stod(str);
    d*=1e9;
    d+=0.5;
    A[i]=(ll)d;
  }

  for(int i=0;i<N;i++){
    //cout << "+" << A[i] << endl;
    ll n=A[i];
    ll n2=0;
    while((n2<20) && (n%2==0)){
      n/=2; n2++;
    }
    //cout << n2  << endl;

    n=A[i];
    ll n5=0;
    while((n5<20) && (n%5==0)){
      n/=5; n5++;
    }

  //cout << n2 << "#" << n5 << endl;
    a[n2][n5]++;

  }


  ll ans=0;

  for(int n2=0;n2<21;n2++){
    for(int n5=0;n5<21;n5++){
      if((2*n2>=18) && (2*n5>=18)){
        ans+=a[n2][n5]*(a[n2][n5]-1)/2;
      }

      
        for(int m5=n5+1;m5<21;m5++){
          if(((n2+n2)>=18) && ((n5+m5)>=18)){
            ans+=a[n2][n5]*a[n2][m5];
          }
        }
      

      for(int m2=n2+1;m2<21;m2++){
        for(int m5=0;m5<21;m5++){
          if(((n2+m2)>=18) && ((n5+m5)>=18)){
            ans+=a[n2][n5]*a[m2][m5];

          }
        }
      }

    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4744
#include <cstdio>
#include <vector>
#include <deque>
#include <utility>
using i64 = long long;

constexpr int mw = 100000;
int n;
std::vector<int> ret, val, w;
std::vector<std::vector<std::pair<int, int>>> qs;

void dfs(const int v, const int depth, const std::vector<int> &dp) {
    auto max(dp);
    for (int i = 1; i < max.size(); i++) {
        if (max[i - 1] > max[i]) max[i] = max[i - 1];
    }
    for (const auto [l, i] : qs[v]) {
        ret[i] = max[l];
    }

    if (depth < 8) {
        for (int i = 0; i < 2; i++) {
            const int to = v * 2 + i;
            if (to > n) break;
            auto next(dp);
            for (int j = 0; j + w[to] <= mw; j++) {
                const int k = dp[j] + val[to];
                if (k > next[j + w[to]]) next[j + w[to]] = k;
            }
            dfs(to, depth + 1, next);
        }
    } else {
        std::deque<int> q { v * 2, v * 2 + 1 };
        while (!q.empty()) {
            const int c = q.front();
            q.pop_front();
            if (c > n) break;
            std::vector<int> anc;
            for (int a = c; a > v; a /= 2) anc.push_back(a);

            if (!qs[c].empty()) {
                const int m = anc.size();
                std::vector<int> subw(1 << m), subv(1 << m);
                for (int i = 0; i < m; i++) {
                    subw[1 << i] = w[anc[i]];
                    subv[1 << i] = val[anc[i]];
                }
                for (int i = 1; i < (1 << m); i++) {
                    const int lsb = i & (i - 1);
                    subw[i] = subw[i ^ lsb] + subw[lsb];
                    subv[i] = subv[i ^ lsb] + subv[lsb];
                }

                for (const auto [l, i] : qs[c]) {
                    for (int j = 0; j < (1 << m); j++) {
                        const int rem = l - subw[j];
                        if (rem < 0) continue;
                        const int a = max[rem] + subv[j];
                        if (a > ret[i]) ret[i] = a;
                    }
                }
            }

            for (int j = 0; j < 2; j++) {
                const int to = 2 * c + j;
                if (to <= n) q.push_back(to);
            }
        }
    }
}

int main() {
    scanf("%d", &n);
    val.resize(n + 1); w.resize(n + 1);
    for (int i = 1; i <= n; i++) scanf("%d%d", &val[i], &w[i]);

    int q;
    scanf("%d", &q);
    qs.resize(n + 1); ret.resize(q);
    for (int i = 0; i < q; i++) {
        int v, l;
        scanf("%d%d", &v, &l);
        qs[v].emplace_back(l, i);
    }

    std::vector<int> dp(mw + 1);
    dp[w[1]] = val[1];
    dfs(1, 0, dp);

    for (const int r : ret) printf("%d\n", r);

    return 0;
}


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

long long ans;

int main()
{
	long long a[3];
	cin>>a[0]>>a[1]>>a[2];
	if(a[0]%2==0||a[1]%2==0||a[2]%2==0)
		ans=0;
	else
	{
		sort(a,a+3);
		ans=a[0]*a[1];
	}
	cout<<ans<<endl;
	return 0;
} 

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

typedef long long ll;
typedef long double ld;

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll a, b, h;

    cin >> a >> b >> h;

    cout << (a + b) * h / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
    static void Main() {
        int[] arr = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        int ans = 0;
        for(int i = arr[0]; i <= arr[1]; i++) if(arr[2] % i == 0) ans++;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 18452
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 #include <iomanip>
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

string S[222222];
int dp[111111][6][6][6];

int red(int x) {
	if(x >= 5)
		return 5;
	return x;
}
int n;
int solve(int i, int a, int b, int c) {
	if(a < 0 || b < 0 || c < 0)
		return 0;
	if(i == n)
		return 1;
	a = red(a);
	b = red(b);
	c = red(c);
	int& ans = dp[i][a][b][c];
	if(ans == -1) {
		ans = 0;
		if(S[i] == "AB") {
			if(solve(i+1, a+1,b-1,c))
				ans = 1;
			else if(solve(i+1, a-1, b+1, c))
				ans = 2;
		} else if(S[i] == "BC") {
			if(solve(i+1, a,b+1,c-1))
				ans = 1;
			else if(solve(i+1, a, b-1, c+1))
				ans = 2;
		} else {
			if(solve(i+1, a+1,b,c-1))
				ans = 1;
			else if(solve(i+1, a-1, b, c+1))
				ans = 2;
		}
	}
	return ans;
}

void solve(istream& cin, ostream& cout) {
	ll a,b,c;
	cin>>n>>a>>b>>c;
	memset(dp, -1, sizeof(dp));
	REP(i, n) {
		S[i] = "";
		cin >> S[i];
	}
	a = red(a), b = red(b), c = red(c);
	if(solve(0, a, b, c)) {
		cout <<"Yes" <<endl;
		REP(i, n) {
//			cout << a << " " << b << " " << c <<endl;
			if(S[i] == "AB") {
				if(solve(i, a,b,c) == 1) {
					a++;b--;
					cout <<"A"<<endl;
				} else {
					a--;b++;
					cout <<"B"<<endl;
				}
			} else if(S[i] == "BC") {
				if(solve(i, a,b,c) == 1) {
					cout <<"B"<<endl;
					b++;c--;
				} else {
					b--;c++;
					cout <<"C"<<endl;
				}
			} else {
				if(solve(i, a,b,c) == 1) {
					a++;c--;
					cout <<"A"<<endl;
				} else {
					a--;c++;
					cout <<"C"<<endl;
				}
			}
		}
	} else {
		cout << "No" <<endl;
	}
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


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

int N, K, S;
vector<int> A;

int main(){
  cin >> N >> K >> S;
  A.resize(N);

  for(int i = 0; i < N; i++){
    if(i < K) A[i] = S;
    else{ if(S == 1 || S == 2) A[i] = S+1; else A[i] = S-1; }
    cout << A[i] << " ";
  }

  cout << endl;
  return 0;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <cstring>
using namespace std;

const int N = 2E5 + 7;
int n,l,r,mid,top,a[N];
struct stack{ int l,r,x; } s[N];

void removex(int l,int r)
{
	if(l > r) return;
	while(top && s[top].l >= l) --top;
	s[top].r = l - 1;
}

int incx(int mx)
{
	int len = s[top].r;
	while(top && s[top].x == mx) --top;
	if(!top) return 0;
	if(s[top].l == s[top].r)
	{
		++s[top].x;
		if(s[top].r < len)
			++top, s[top] = (stack){ s[top - 1].r + 1,len,1 };
	}
	else
	{
		s[top + 1] = (stack){ s[top].r,s[top].r,s[top].x + 1 },
		--s[top].r, ++top;
		if(s[top].r < len)
			++top, s[top] = (stack){ s[top - 1].r + 1,len,1 };
	}
	return 1;
}

int checkx(int x)
{
	s[top = 1] = (stack){ 1,a[1],1 };
	for(int i = 2;i <= n; ++ i)
		if(a[i] > a[i - 1]) ++top, s[top] = (stack){ a[i - 1] + 1,a[i],1 };
		else
		{
			removex(a[i] + 1,a[i - 1]);
			if(!incx(x)) return 0;
		}
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n; ++ i) scanf("%d",a + i);
	
	l = 1, r = n;
	while(l <= r)
	{
		mid = l + r >> 1;
		if(checkx(mid)) r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n",l);
	
	return 0;
}

Measured memory_bytes: 4756
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string s; cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
    return 0;
}


Measured memory_bytes: 3544
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type.Int

const val P = 1000000007L

// Find (x, y, r) such that r = gcd(a,b) and ax + by = r.
fun extendedGCD(a: Long, b: Long): Triple<Long, Long, Long> {
  var x0 = 1L
  var y0 = 0L
  var z0 = a
  var x1 = 0L
  var y1 = 1L
  var z1 = b
  while (true) {
    if (z1 == 0L) return Triple(x0, y0, z0)
    val q = z0 / z1
    val x2 = x0 - q * x1
    val y2 = y0 - q * y1
    val z2 = z0 - q * z1
    x0 = x1
    x1 = x2
    y0 = y1
    y1 = y2
    z0 = z1
    z1 = z2
  }
}

fun inverseMod(a: Long, m: Long): Long {
  val (x, y, r) = extendedGCD(a, m)
  if (r != 1L) return 0  // No inverse.

  return (x + m) % m
}

fun timesMod(x: Long, y: Long): Long {
  return x * y % P
}

fun plusMod(x: Long, y: Long): Long {
  return (x + y) % P
}

fun minusMod(x: Long, y: Long): Long {
  return (x - y + P) % P
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val factorialTable = LongArray(n)
  factorialTable[0] = 1
  for (k in 1..(n - 1)) {
    factorialTable[k] = (factorialTable[k - 1] * k) % P
  }
  val inverseFactorialTable = factorialTable.map { inverseMod(it, P) }.toLongArray()

  val fTable = Array(n, { k ->
    if (2 * k < n) 0
    else timesMod(
        timesMod(factorialTable[k], factorialTable[k - 1]), inverseFactorialTable[2 * k - n])
  })

  var ans = 0L
  for (k in 1..(n - 1)) {
    val count = minusMod(fTable[k], fTable[k - 1])
    ans = plusMod(ans, timesMod(count, k.toLong()))
  }
  println(ans)
}

Measured memory_bytes: 124180
// see https://github.com/LumaKernel/vimfiles/tree/master/snippets/cp-cpp/temp.snip
/// --- .lumrc Template {{{ ///
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = tuple<ll, ll>;
using P3 = tuple<ll, ll, ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VP = vector<P>;
using VS = vector<string>;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define FORI(i,a,b) for(int i=int(a);i<=int(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPI(i,n) FORI(i,0,n)
#define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define RFORI(i,a,b) for(int i=int(b);i>=int(a);--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPI(i,n) RFORI(i,0,n)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique(ALL(a)),(a).end())
#define PB push_back
#define EACH(i,c) REP(i,(c).size())
#define REACH(i,c) RREP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))

#define BR cout<<"\n";

#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
#else
#define dump(...)
#endif

#define YES(x) cout<<((x)?"YES":"NO")<<"\n";
#define Yes(x) cout<<((x)?"Yes":"No")<<"\n";
#define yes(x) cout<<((x)?"yes":"no")<<"\n";

inline int omajinai_int_in(){omajinai;int n;cin>>n;return n;}
inline ll omajinai_ll_in(){omajinai;ll n;cin>>n;return n;}
inline string omajinai_string_in(){omajinai;string n;cin>>n;return n;}
inline int int_in(){int n;cin>>n;return n;}
inline ll ll_in(){ll n;cin>>n;return n;}
inline string string_in(){string n;cin>>n;return n;}
#define oini omajinai_int_in()
#define oinl omajinai_ll_in()
#define oins omajinai_string_in()
#define ini int_in()
#define inl ll_in()
#define ins string_in()

#define isInside(y,x) (0<=(y)&&(y)<h&&0<=(x)&&(x)<w)

#define fi(x) (get<0>(x))
#define se(x) (get<1>(x))
#define th(x) (get<2>(x))
#define fo(x) (get<3>(x))
#define fif(x) (get<4>(x))

template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; EACH(i, v) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "}";  return o; }

template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }

template <typename T> inline void smax(T &a, T b) { a = a > b ? a : b; }
template <typename T> inline void smin(T &a, T b) { a = a < b ? a : b; }

constexpr double PI = acos(-1);

/// }}}--- ///

constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr int MOD = 1e9+7;

int main() {
  int a=ini,b=ini;
  if(a%b==0) cout << -1 << endl;
  else cout << a << endl;
}

//


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

int main(){
    int n;
    cin>>n;
    string a,b,c;
    cin>>a>>b>>c;
    int ans=0,cnt=0;

    for(int i=0;i<n;i++){
        cnt=0;
        if(a[i]==b[i]) cnt++;
        else if(a[i]==c[i]) cnt++;
        if(b[i]==c[i]) cnt++;
        //0 to 2,1 to 1,2 to 0
        ans+=2-cnt;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256