akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

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

    if(A == 5)
        if(B == 5){
            if(C == 5)
                cout << "NO";
            else
                cout << "YES";
        }else{
            if(C == 5)
                cout << "YES";
            else
                cout << "NO";
        }
    else
        if(B == 5){
            if(C == 5)
                cout << "YES";
        }else
            cout << "NO"; 
        
}

Measured memory_bytes: 3628
D = {}
D["A"] = input()
D["B"] = input()
D["C"] = input()

t = "A"
while 1:
    if len(D[t]) == 0:
        winner = t
        break
    if D[t][0] == "a":
        u = "A"
    elif D[t][0] == "b":
        u = "B"
    elif D[t][0] == "c":
        u = "C"
    D[t] = D[t][1:]
    t = u
print(winner)


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

int h, w;
string s[12];

int qina(vector<int> v) {
  int sole = w % 2;
  int used[12] = {};
  for(int i = 0; i < w; i++) {
    int ok = 0;
    if(used[i]) continue;
    used[i] = 1;
    for(int j = i + 1; j < w; j++) if(!used[j]) {
      int okk = 1;
      for(int k = 0; k < h; k++)
        if(s[v[k]][i] != s[v[h - 1 - k]][j]) { okk = 0; break; }
      if(okk) {
        used[j] = 1;
        ok = 1;
        break;
      }
    }
    if(ok) continue;
    if(sole--) {
      int okk = 1;
      for(int k = 0; k < h; k++)
        if(s[v[k]][i] != s[v[h - 1 - k]][i]) { okk = 0; break; }
      if(!okk) return 0;
      continue;
    }
    return 0;
  }
  return 1;
}

int ecas(int y, int c, vector<int> v, set<int> u) {
  if(y == 0) {
    if(qina(v)) return 1;
    return 0;
  }
  if(y % 2 == 1) {
    for(int i = 0; i < h; i++) {
      auto tv = v;
      auto tu = u;
      tv[h / 2] = i;
      tu.emplace(i);
      if(ecas(y - 1, 0, tv, tu)) return 1;
    }
    return 0;
  }
  int f = 0;
  for(int i = 0; i < h; i++) if(!u.count(i)) { f = i; break; }

  for(int i = 0; i < h; i++) if(!u.count(i) && f != i) {
    auto tv = v;
    auto tu = u;
    tv[c] = f;
    tv[h - 1 - c] = i;
    tu.emplace(f);
    tu.emplace(i);
    if(ecas(y - 2, c + 1, tv, tu)) return 1;
  }
  return 0;
}

int solve() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> h >> w;
  for(int i = 0; i < h; i++) cin >> s[i];
  return ecas(h, 0, vector<int>(h), set<int>());
}

int main() {
  cout << (solve() ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "1" ].parse.expand.solve == "Hello World" );
	assert( [ "2", "3", "5" ].parse.expand.solve == "8" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	auto a = 0L;
	auto b = 0L;
	if( n == 2 )
	{
		input.popFront;
		a = input.front.strip.to!( long );
		input.popFront;
		b = input.front.strip.to!( long );
	}
	return tuple( n, a, b );
}

auto solve( long n, long a, long b )
{
	if( n == 1 ) return "Hello World";
	else         return ( a + b ).to!string;
}


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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  vector<string>S(N);
  for(int i = 0; i < N; i++) {
  cin >> S[i]; 
  }
  set<string>a;
  for(int i = 0; i < N; i++) {
  a.insert(S[i]);
  }
  cout << a.size() << endl;
}


Measured memory_bytes: 24936
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


N = int(input())
*A, = map(int, input().split())
m = max(A)
c = [0]*(m+1)
for i in range(N):
    c[A[i]] += 1

pc = True
for i in range(2, m):
    k = i
    same = 0
    while k <= m:
        same += c[k]
        k += i
        if same >= 2:
            break
    if same >= 2:
        pc = False
        break

if pc:
    print("pairwise coprime")
else:
    g = gcd(A[0], A[1])
    for i in range(2, N):
        g = gcd(g, A[i])
    if g == 1:
        print("setwise coprime")
    else:
        print("not coprime")


Measured memory_bytes: 215624
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

# https://qiita.com/jkr_2255/items/95a0c0a573baa1578121
def factorial(n)
  arr = [*1..n]
  loop do
    return arr[0] if arr.length == 1
    arr = arr.each_slice(2).map { |a, b| b ? a * b : a }
  end
end

N, M = gets_i_list
MOD = 10**9 + 7

if N != M && N - 1 != M && N != M - 1
  puts 0
  exit
end

if N == M
  puts (factorial(N) * factorial(M) * 2) % MOD
else
  a, b = 0, 0
  if N > M
    a = N
    b = M
  else
    a = M
    b = N
  end
  puts (factorial(b)**2 * a) % MOD
end


Measured memory_bytes: 12896
import sys
def maxcost(li,n):
    dp=[[-1 for j in range(3)] for i in range(n)]
    dp[n-1][0],dp[n-1][1],dp[n-1][2]=li[n-1][0],li[n-1][1],li[n-1][2]
    for i in range(n-2,-1,-1):
        for j in range(3):
            mx=-sys.maxsize
            for k in range(3):
                if j!=k:
                    mx=max(mx,dp[i+1][k]+li[i][j])
            dp[i][j]=mx
    return max(dp[0][0],dp[0][1],dp[0][2])

n=int(input())
li=[]
for i in range(n):
    temp=[int(x) for x in input().split()]
    li.append(temp)
print(maxcost(li,n))

Measured memory_bytes: 45620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int n;
    cin >> n;
    cout << n / 2 + n % 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9+7;

int main()
{   
    fastio
    int x;
    cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 3652
/**
 * Header Files
 */
#include <bits/stdc++.h>

/**
 * Namespace declaration
 */
using namespace std;



int main(void){
    int X, A;
    cin >> X >> A;

    if(X<A){
        cout << 0;
    }else{
        cout << 10;
    }

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1e18
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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;}

int main(){
    int n;
    cin>>n;
    int cnt=0;
    for(int i=1;i<=n-1;++i){
        int m=n-i;
        map<int,int>a;
        set<int>b;
        for(int j=2;j*j<=m;++j){
            if(m%j==0){
                b.insert(j);
                while(m%j==0){
                    m/=j;
                    a[j]++;
                }
            }
        }
        if(m!=1){a[m]++;b.insert(m);}
        int ans=1;
        for(auto x:b){
            ans*=a[x]+1;
        }
        cnt+=ans;
    }
    
    cout<<cnt<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <complex>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
	double D;
	double vx,vy;
	double px,py;
	while( cin >> D >> px >> py >> vx >> vy && D ){
		if( fabs(px * vy - vx * py) < 1e-9 ){
			double d = sqrt(vx*vx+vy*vy);
			vx /= d;
			vy /= d;
			double distance = sqrt(px*px+py*py);
			double ans = distance;
			
			double PX = px + vx * distance;
			double PY = py + vy * distance;
			if(sqrt(PX*PX+PY*PY)>1e-9){
				double TX = vx - px;
				double TY = vy - py;
				ans += 2 * sqrt(TX*TX+TY*TY);
			}
			if( ans < D + 1e-9 ){
				printf("%.8lf\n",ans);
			}else{
				cout << "impossible" << endl;
			}
		}else{
			cout << "impossible" << endl;
		}
	}
}

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

int main() {
  // ここにプログラムを追記
int a,b;
double c;
  cin >> a >> b;
  a += b;
  c = a;
  a /= 2;
  c /= 2;
  if (c>a)
	cout << a+1 << endl;
  else
	cout << a << endl;
}


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

int main() {
  char x;
  cin >> x;
  if (x == 'C') cout << 'G' << endl;
  else if (x == 'G') cout << 'C' << endl;
  else if (x == 'A') cout << 'T' << endl;
  else if (x == 'T') cout << 'A' << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> s(N);
    ll sum = 0;
    for (int i = 0; i < N; i++)
    {
        ll x;
        cin >> x;
        sum += x;
        s[i] = x;
    }
    SORT(s);

    if (sum % 10 != 0)
    {
        cout << sum << endl;
        return 0;
    }
    else
    {
        int index = 0;
        REP(i, N)
        {
            if ((sum - s[i]) % 10 != 0)
            {
                cout << sum - s[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
    }

    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, P;
    ll temp;
    ll ans = 1;
    vector<pair<ll, ll>> prime;
    cin >> N >> P;
    temp = P;
    for(ll i = 2;i * i <= temp;i++) {
        ll count = 0;
        while(temp % i == 0) {
            temp /= i;
            count++;
        }
        if(count > 0) prime.push_back({i, count});
    }
    prime.push_back({temp, 1});
    iter(i, prime) {
        ll temp2 = i.second / N;
        if(temp2 > 0) {
            ll aaaa = 1;
            while(temp2--) aaaa *= i.first;
            ans *= aaaa;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int d, t, s;
    cin >> d >> t >> s;
    yorn(d <= t * s);
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;


int main()
{
	ll n, k;
	cin >> n >> k;
	vecll d(n);
	for (int i = 0;i < n;i++) {
		cin >> d[i];
	}
	ll ans = INF;
	for (int i = 0;i <= n-k;i++) {
		ans = min(ans, abs(d[i]) + abs(d[i] - d[i + k - 1]));
		ans = min(ans, abs(d[i + k - 1]) + abs(d[i] - d[i + k - 1]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
using P = std::pair<int, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n,d[555][555],p[555*555],e[555][555];
std::deque<int> que;

bool check(int i, int j){
	return (0<=i && i<n && 0<=j && j<n);
}

int main(void){
	int m,i,j,k,v,x,y,ans=0,dx[4]={-1,0,0,1},dy[4]={0,-1,1,0};
	std::cin >> n;
	m = n*n;
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			e[i][j] = 1;
			d[i][j] = std::min({i,n-i-1,j,n-j-1});
		}
	}
	for(i=0; i<m; ++i){
		std::cin >> p[i]; --p[i];
		x = p[i]/n; y = p[i]%n;
		ans += d[x][y];
		e[x][y] = 0;
		que.push_back(p[i]);
		while(!que.empty()){
			v = que.front();
			que.pop_front();
			x = v/n; y = v%n;
			for(k=0; k<4; ++k){
				if(!check(x+dx[k],y+dy[k])){
					continue;
				}
				if(d[x][y]+e[x][y]<d[x+dx[k]][y+dy[k]]){
					// printf("(%d, %d)->(%d, %d): %d, %d\n",x,y,x+dx[k],y+dy[k],d[x][y],e[x][y]);
					d[x+dx[k]][y+dy[k]] = d[x][y]+e[x][y];
					if(e[x][y]){
						que.push_back((x+dx[k])*n+y+dy[k]);
					}else{
						que.push_front((x+dx[k])*n+y+dy[k]);
					}
				}
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 7128
#include <iostream>
#include <vector>

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;

    lint ans = 1000;
    for (int i = 0; i + 1 < n; ++i) {
        if (xs[i] >= xs[i + 1]) continue;
        lint got = ans / xs[i];
        ans += got * (xs[i + 1] - xs[i]);
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3656
S=input()
K=int(input())
SS=S+S
SSS=SS+S
count_single=count_double=count_triple=0
flag=True
for i in range(1, len(S)):
  if not flag:
    flag=True
    continue
  if S[i-1]==S[i]:
    count_single+=1
    flag=False
flag=True
for i in range(1, len(SS)):
  if not flag:
    flag=True
    continue
  if SS[i-1]==SS[i]:
    count_double+=1
    flag=False
flag=True
for i in range(1, len(SSS)):
  if not flag:
    flag=True
    continue
  if SSS[i-1]==SSS[i]:
    count_triple+=1
    flag=False
if K==1:
  print(count_single)
elif K==2:
  print(count_double)
else:
  diff21=count_double-count_single
  diff32=count_triple-count_double
  print(count_single+(K//2)*diff21+((K-1)//2)*diff32)

Measured memory_bytes: 38384
package main

import(
  "fmt"
  "strings"
)

func main(){
  var S string
  
  fmt.Scan(&S)

  if strings.Contains(S,"W") != strings.Contains(S,"E"){
    fmt.Println("No")
  }else if strings.Contains(S,"S") != strings.Contains(S,"N"){
    fmt.Println("No")
  }else{
    fmt.Println("Yes")
  }
}

Measured memory_bytes: 640
def main():
  n = int(input())
  p = list(map(int, input().split(' ')))
  c = 0
  if judge(p):
    print('YES')
  else:
    for i in range(n):
      for j in range(i+1, n):
        a = p.copy()
        a[i], a[j] = a[j], a[i]
        if judge(a):
          c += 1
          print('YES')
    if c == 0:
      print('NO')


def judge(l):
  return True if l == sorted(l) else False


if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
   int n,t,a;
   cin>>n>>t>>a;
   double sa=1000000000;
   int ans=0;
   for(int i=0;i<n;i++){
      int x;
      cin>>x;
      double k=t-a-x*0.006;
      if(k<0)k=-k;
      if(sa>k){
         sa=k;
         ans=i+1;
      }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <queue>
 
using namespace std;
typedef long long LL;
 
template<typename T>
void print_vec(vector <T>v){
  for(int i=0;i<v.size();i++){
	cout << v[i] << " ";
  }
  cout << endl;
}
 
int main(){
  LL K;
  cin >> K;
  int N=K/10000000000000000;
  if(N<2){
	N=2;
  }
N=N+1;
if(N>50){
N=50;
}
  cout << N <<endl;
  vector<LL> a(N,N-1+K/N);
  for(int i=0;i<K%N;i++){
	a[i]+=N-(K%N-1);
  }
  for(int i=K%N;i<N;i++){
	a[i]-=K%N;
  }
  print_vec(a);
 
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int n, d;
int points[10][10];

int isInteger(int a[10], int b[10]) {
    int sum = 0, i, dist;
    for (i = 0; i < d; i++) {
        dist = a[i] - b[i];
        sum += dist *= dist;
    }
    for (i = 1; i <= 400; i++) {
        if (i*i == sum) return 1;
    }
    return 0;
}

int main(void) {
    int i, j, ans=0;
    cin >> n >> d;
    for (i = 0; i < n; i++) {
        for (j = 0; j < d; j++) {
            cin >> points[i][j];
        }
    }
    for (i = 0; i < n-1; i++) {
        for (j = i+1; j < n; j++) {
            ans += isInteger(points[i], points[j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int a[110];
int main()
{
	int n;
	scanf("%d",&n);
	int sum = 0;
	for(int i = 1;i <= n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
	}
	double ave = sum*1.0/n;
	int idx;
	double minn = 1000;
	for(int i = 1;i <= n;i++){
        if(abs(a[i]-ave)<minn){
            minn = abs(a[i]-ave);
            idx = i;
        }

	}
	printf("%d",idx-1);
	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.math;
import std.format;

void main() {
  foreach (string line; stdin.lines) {
    double a, b;
    line.formattedRead("%f %f\n", &a, &b);

    writef("%.0f ", gcd(a, b));
    writef("%.0f\n", lcm(a, b));
  }
}

double gcd(double x, double y) {
  while (y != 0) {
    x = x % y;
    swap(x, y);
  }
  return x;
}

double lcm(double x, double y) {
  return x / gcd(x, y) * y;
}

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

using namespace std;

#define int long long
#define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

double p[3000];
double dp[3030][3030];

signed main() {
    LCIN(N);
    REP(i, N) cin >> p[i];
    dp[0][0] = 1;
    cout << fixed << setprecision(12);
    REP(i, N) REP(j, N) {
        dp[i + 1][j] += dp[i][j] * (1 - p[i]);
        dp[i + 1][j + 1] += dp[i][j] * p[i];
    }
    double ans = 0;
    FOR(j, N / 2 + 1, N + 1) ans += dp[N][j];
    cout << ans << "\n";
}


Measured memory_bytes: 143616
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<pair<pair<int,int>,int>> viii;
typedef vector<pair<pair<ll,ll>,ll>> viiil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000
#define MOD 1000000007;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int sm = 0;
    while (b <= a) {
        b *= 2;
        sm++;
    }
    while (c <= b) {
        c *= 2;
        sm++;
    }
    if (sm > k) {
        cout << "No" << '\n';
    }
    else {
        cout << "Yes" <<  '\n';
    }
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    //querySolve();
    solve();

}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

typedef long double ld;

ld N;
int main(){
	fast;
	
	cin>>N;
	
	cout<<setprecision(9)<<pow(N/3,3);
	
}


Measured memory_bytes: 640
# from pprint import pprint
# import math
# import collections

s = input()
t = input()
# n, k = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))

max_cnt = 0
for i in range(len(s) - len(t) + 1):
    _s = s[i:i + len(t)]

    cnt = 0
    for j in range(len(t)):
        if _s[j] == t[j]:
            cnt += 1

    # print(_s,t, 'match', cnt)

    if max_cnt < cnt:
        max_cnt = cnt

print(len(t) - max_cnt)


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

using namespace std;
set<int> s1;
const int MAXN = 3e5+5;
int obs[MAXN];
int arr[MAXN];
long long ans;
map<long long,int> m1;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        
        cin>>arr[i];
    }
    for(int i=1;i<=n;i++){
        ans+=m1[i-arr[i]];
        m1[arr[i]+i]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 27108
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    map<string, int> mp;
    rep(i,n) mp[s[i]] ++;
    cout << "AC x " << mp["AC"] <<"\n";
    cout << "WA x " << mp["WA"] <<"\n";
    cout << "TLE x " << mp["TLE"] <<"\n";
    cout << "RE x " << mp["RE"] <<"\n";
    return 0;
}


Measured memory_bytes: 6428
# E - This Message Will Self-Distruct in 5s

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n

# Aj - j の各値の個数
diff = Counter(a[j] - (j+1) for j in range(n))

# Aj - j == -Ai - i となる(i,j)の個数
count = sum(diff[-a[i] - (i+1)] for i in range(n))
print(count)


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

#define int long long
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; }

signed main(){
	int n;
	cin >> n;
	vector<int> lis;

	set<int> ans;

	for(int i = 1;i*i <= n;i++){
		if(n % i == 0){
			if(i != 1) lis.push_back(i);
			if(n / i != i){
				lis.push_back(n/i);
			}
		}
	}

	int m = n-1;
	for(int i = 1;i*i <= m;i++){
		if(m % i == 0){
			if(n % i != 0) ans.insert(i);
			int j = m / i;
			if(i != j && n % j != 0){
				ans.insert(j);
			}
		}
	}

	for(auto e : lis){
		int tmp = n;
		while(tmp >= e){
			if(tmp % e == 0) tmp /= e;
			else break;
		}
		if(tmp % e == 1) ans.insert(e);
	}

	cout << ans.size() << endl;

	return 0;
}


Measured memory_bytes: 384
N = int(input())
L = list(map(int,input().split()))
L.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return  x
LCM = L[0]
for i in range(1,N):
  A = max(L[i],LCM)
  B = min(L[i],LCM)
  cur = gcd(A,B)
  if cur == 1:
    LCM *= L[i]
  else:
    LCM = LCM*L[i]//cur
LCM -= 1
ans = 0
for i in range(N):
  ans += LCM%L[i]
print(ans)

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

int main(){
  int N,L;
  int eat;
  cin >> N >> L;
  int end = L+N-1;
  int sum = N*L + N*(N-1)/2;
  if(L*end <= 0){
    eat = 0;
  }
  else if(L*end > 0 && end < 0){
    eat = max(L,end);
  }
  else if(L*end > 0 && end > 0){
    eat = min(L,end);
  }
  cout << sum-eat << endl;
  return 0;
}

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

signed main(){
  int H,A;
  cin>>H>>A;
  
  int ans=0;
  if(H%A==0){
    ans=H/A;
  }else{
    ans=H/A;
    ans++;
  }
  cout<<ans<<endl;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}
template <typename T>
T gcd(const T x, const T y) {
  if (x == 0) {
    return y;
  } else if (y == 0) {
    return x;
  } else if (x < y) {
    return gcd(x, y % x);
  } else if (y < x) {
    return gcd(y, x % y);
  } else {
    return x;
  }
}

template <typename T>
T lcm(const T x, const T y) {
  if (x == 0 || y == 0) {
    return 0;
  } else {
    return x / gcd(x, y) * y;
  }
}

int main() {
  int64_t n;
  std::cin >> n;
  int64_t ta = 1, aa = 1;
  for (int i = 0; i < n; i++) {
    int64_t t, a;
    std::cin >> t >> a;
    int64_t r = 1;
    r = std::max(r, (ta - 1) / t + 1);
    r = std::max(r, (aa - 1) / a + 1);
    ta = t * r;
    aa = a * r;
  }
  std::cout << ta + aa << std::endl;
  return 0;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int a,b,c; cin >> a>>b>>c;
    
    YES(b-a==c-b);
}


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

ll digit(ll x) {
  ll count=0;
  while (x>0) {
    x = x/10;
    count++;
  }
  return count;
}
ll dig_sum(ll x) {
  ll sum=0;
  while (x>0) {
    sum += x%10;
    x = x/10;
  }
  return sum;
}

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
 
  ll sum=0;
  for (ll i=1;i<=n;i++) {
    if (a<=dig_sum(i) && dig_sum(i)<=b) {
      sum += i;
    }
  }
  
  cout << sum;
}

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

using namespace std;

int main(){
	string S[3];
	cin >> S[0] >> S[1] >> S[2];

	int turn = 0;
	while(true){
		if (S[turn].size() == 0){
			break;
		}
		int c = S[turn][0] - 'a';
		S[turn].erase(S[turn].begin());
		turn = c;
	}

	cout << (char)('A' + turn) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

int fib(int n)
{
    if (n == 0 || n == 1) return dp[n] = 1;
    if ( dp[n] != -1) return dp[n];
    return dp[n] = fib(n - 1) + fib(n - 2);
}

int main()
{
    int n;
    for (int i = 0; i < 50; i++) dp[i] = -1;

    scanf("%d", &n);
    printf("%d\n", fib(n));
    return 0;
}


Measured memory_bytes: 2100
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    arr = factorization(n)

    res = 0

    for i in arr:
        res += sankaku(i[1])

    if n == 1:
        res = 0

    return res

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def sankaku(n):
    res = 1

    while True:
        if res * (res + 1) // 2 <= n < (res + 1) * (res + 2) // 2:
            break

        res += 1

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31196
#include<stdio.h>

int main(void)
{
	int i,j,N,minj,save;
	int count=0;
	scanf("%d",&N);
	int data[100];

	for(i=0;i<N;i++)
	{
		scanf("%d",&data[i]);
	}

	for(i=0;i<N;i++)
	{
		minj=i;
		for(j=i;j<N;j++)
		{
			if(data[j]<data[minj])
			minj=j;
		}
		if(i!=minj)
		{
			save=data[i];
			data[i]=data[minj];
			data[minj]=save;
			count++;
		}
		
	}
	
	printf("%d",data[0]);
	for(i=1;i<N;i++)
	{
		printf(" %d",data[i]);
	}
	printf("\n");
	printf("%d\n",count);


}


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

int main(){
    string S;
    cin>>S;
    int size = S.length();
    string O="", I="";
    for(int i=0;i<size;i++){
        O+=to_string(i%2);
        I+=to_string((i+1)%2);
    }
    
    int Ocount=0;
    int Icount=0;
    for(int i=0;i<size;i++){
        if(S[i]==O[i])Ocount++;
        if(S[i]==I[i])Icount++;
    }

    int ans;
    if(Ocount<Icount)ans=Ocount;
    if(Icount<=Ocount)ans=Icount;
    cout<<ans <<endl;
    return 0;
}

Measured memory_bytes: 768
/*
Binary Tree
*/

#include<stdio.h>
#include<stdlib.h>

typedef struct{
	int l;	//left child
	int r;	//right child
	int p;	//parent
}Node;

void calc_height(Node*,int,int);

int hei;

int main(void){
	int n,id,sib,deg,dep;
	int i,j;
	int work;
	Node *node;

	scanf("%d",&n);

	node=(Node*)malloc(n*sizeof(Node));

	for(i=0;i<n;i++){
		 node[i].p=-1;
		 node[i].l=-1;
		 node[i].r=-1;
	}

	for(i=0;i<n;i++){
		scanf("%d",&id);
	
		scanf("%d",&node[id].l);
		if(node[id].l != -1) node[node[id].l].p=id;
		
		scanf("%d",&node[id].r);
		if(node[id].r != -1) node[node[id].r].p=id;

	}

	for(i=0;i<n;i++){
		printf("node %d: ",i);

		printf("parent = %d, ",node[i].p);
		
		sib=-1;
		if(node[i].p!=-1){
			if(node[node[i].p].l==i) sib=node[node[i].p].r;
			else sib=node[node[i].p].l;
		}
		printf("sibling = %d, ",sib);

		deg=0;
		if(node[i].l!=-1) deg++;
		if(node[i].r!=-1) deg++;
		printf("degree = %d, ",deg);

		dep=0;
		work=i;
		while(node[work].p!=-1){
			dep++;
			work=node[work].p;
		}
		printf("depth = %d, ",dep);

		hei=0;
		calc_height(node,i,1);
		printf("height = %d, ",hei);
		
		if(node[i].p==-1) printf("root\n");
		else if(node[i].l==-1 && node[i].r==-1) printf("leaf\n");
		else printf("internal node\n");
	}

	free(node);

	return 0;
}


void calc_height(Node node[],int id,int cnt){
	if(node[id].l==-1 && node[id].r==-1) return;
	if(cnt>hei) hei=cnt;
	if(node[id].r!=-1)calc_height(node,node[id].r,cnt+1);
	if(node[id].l!=-1)calc_height(node,node[id].l,cnt+1);	
}

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

int main(){
	int n;
	cin>>n;
	
	vector<int>p(n,0);
	
	int f=0, cnt=1;
	
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	
	for(int i=0;i<n-1;i++){
		if(p[i]<p[i+1]){
			if(f==0){
				f=1;
			}
			else if(f==2){
				cnt++;
				f=0;
			}
		}
		else if(p[i]>p[i+1]){
			if(f==0){
				f=2;
			}
			else if(f==1){
				cnt++;				
				f=0;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

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

    string s;
    cin >> s;

    int count = 0;

    for (int i  = 0; i < n-1; i++) {
        if (s[i] != s[i+1]) 
            count++;
    }
    count++;

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }


signed main()
{
    int N; cin>>N;
    vector<int> b(N);
    int X=0;
    for(int i=0;i<N;i++){
        int a; cin>>a;
        b[i]=a&-a;
        X^=a;
    }
    sort(b.begin(),b.end(),greater<int>());

    int ans=0;
    for(int i=0;i<N;i++){
        //cout<<(bitset<10>)X<<' '<<(bitset<10>)b[i]<<endl;
        if(X&b[i]){
            ans++;
            X^=b[i];
            X^=(b[i]-1);
        }
    }
    if(X==0){
        cout<<ans<<endl;
    }else{
        cout<<-1<<endl;
    }
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    long ans = 1;
    long p = 998244353;
    List<Integer> list = new ArrayList<>();
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(sc.next());
      if((i == 0 && n != 0) || (i != 0 && n == 0)){
        System.out.println(0);
        return;
      }
      list.add(n);
    }
    Collections.sort(list);
    long count = 1;
    long count2 = 0;
    long now = 1;
    for(int i = 1; i < N; i++){
      int n = list.get(i);
      if(n == now){
        ans *= count;
        ans%= p;
        count2++;
      }else{
        if(n != now+1){
          ans = 0;
        }
        count = count2;
        count2 = 1;
        ans *= count;
        ans %= p;
        now = n;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 48084
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define REP(i,n) for(int i=0;i<signed(n);i++)
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
const ll MOD = 1000000007;
const ll INF = 9e9;
ll N,M,ans=INF;
ll A[300010]={},S[301000]={};
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        cin>>A[i];
        S[i]+=A[i];
        S[i+1]=S[i];
    }
    //a:右半分の区切り i:真ん中 b:左半分
    //s:右の和 t:左の和
    ll a=0,b=2,s,t;
    REP(i,N-2){
        if(i==b)b++;
        s=(S[i]-S[a])-S[a];
        t=(S[N-1]-S[b])-(S[b]-S[i]);
        bool f=true;
        if(i==0)continue;
        while(f){
            f=false;
            if(a+1==i)continue;
            if(abs(s)>abs(s-A[a+1]*2)){
                s-=A[a+1]*2;
                a++;f=true;
            }
        }
        f=true;
        while(f){
            f=false;
            if(b+1==N-1||b==N-1)continue;
            if(abs(t)>abs(t-A[b+1]*2)){
                t-=A[b+1]*2;
                b++;f=true;
            }
        }
        ans=min( ans,( max({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]})
        -min({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]}) ) );
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
  using namespace std;
  #define int long long int
  #define vi vector<int>
  #define pii pair<long long ,long long>
  #define pll pair<int,int>
  #define mod 1000000007
  #define hell 998244353
  #define all(x) x.begin(),x.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define eb push_back
  #define ff first
  #define ss second
  #define rep(n) for(int i=0;i<n;i++)
  #define lb lower_bound
  #define up upper_bound
  int dp[3005][3005];
  void solve()
  { 
     
     int n;
     cin>>n;
     int sum=0;
     vi v(n);
     rep(n)
      {cin>>v[i];
       sum+=v[i];
      }

      for(int gap=0;gap<n;gap++)
      {
         for(int i=0,j=gap;j<n;i++,j++)
         {
              // f(i,j)=max(vi,min(f(i+2,j),f(i+1,j-1)),vj+min(f(i+1,j-1),f(i,j-2)))
           
            int x=i+2<=j?dp[i+2][j]:0;
            int y=i+1<=j-1?dp[i+1][j-1]:0;
            int z=i<=j-2?dp[i][j-2]:0;

            dp[i][j]=max(v[i]+min(x,y),v[j]+min(y,z));            
         }
      }

      cout<<dp[0][n-1]-(sum-dp[0][n-1]);



   

  






  }



  signed main()
  {

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


   
    
    
    int T;
    T=1;
    
    while(T--)
    {
      solve();
    }
    return 0;
  }

Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int H, W, N; 
cin >> H >> W >> N; 
long long int X[900010] = {}; 
long long int count = 0; 
for(int i = 0; i < N; i++){
long long int A, B;
cin >> A >> B; 
long long int K = (A-1) * W + B; 
if(A != 1 && A != 2 && B != 1 && B != 2) {X[count] = K - W - 1;  
count ++; 
}
if(A != 1 && A != 2 && B != 1 && B != W) {X[count] = K - W;  
count ++; 
}
if(A != 1 && A != 2 && B != W-1 && B != W) {X[count] = K - W + 1;  
count ++; 
}
if(A != 1 && A != H && B != 1 && B != 2) {X[count] = K - 1;  
count ++; 
}
if(A != 1 && A != H && B != 1 && B != W){X[count] = K;  
count ++; 
}
if(A != 1 && A != H && B != W-1 && B != W) {X[count] = K + 1;  
count ++; 
}
if(A != H-1 && A != H && B != 1 && B != 2){X[count] = K + W - 1;  
count ++; 
}
if(A != H-1 && A != H && B != 1 && B != W) {X[count] = K + W;  
count ++; 
}
if(A != H-1 && A != H && B != W-1 && B != W) {X[count] = K + W + 1;  
count ++; 
}
}
sort(X, X+900000, greater<long long int>()); 
long long int Y[12] = {};
long long int count2 = 1; 
for(int i = 0; i <= 900000; i++){
if(X[i] == X[i+1]){
count2 ++;
}
else{
Y[count2] ++; 
count2 = 1; 
}
if(X[i] == 0){
break; 
}
}
Y[0] = (H-2) * (W-2) - Y[1]-Y[2]-Y[3]-Y[4]-Y[5]-Y[6]-Y[7]-Y[8]-Y[9];  
cout << Y[0] << endl; 
cout << Y[1] << endl; 
cout << Y[2] << endl; 
cout << Y[3] << endl; 
cout << Y[4] << endl; 
cout << Y[5] << endl; 
cout << Y[6] << endl; 
cout << Y[7] << endl; 
cout << Y[8] << endl; 
cout << Y[9] << endl; 
}

Measured memory_bytes: 7424