akhauriyash/Code-Regression huggingface dataset:
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 2e5+2;


void solve()
{
    ll n, d;
    lscn(n); lscn(d);

    int cnt = 0;

    rep(i, 0, n) {
        ll x, y;
        lscn(x); lscn(y);

        ll dist = abs(x * x) + abs(y * y);

        if(dist <= (d * d)) {
            cnt ++;
        }
    }

    prin(cnt);
}

int main()
{
    int t = 1;
    // scn(t);
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3820
N, M = map(int, input().split())
A = list(map(int, input().split()))

t = {}
c = 0
for a in A:
    c += a
    c %= M
    if c in t:
        t[c] += 1
    else:
        t[c] = 1

result = 0
if 0 in t:
    result += t[0]
c = 0
for a in A:
    c += a
    c %= M
    t[c] -= 1
    result += t[c]
print(result)


Measured memory_bytes: 14224
#include <iostream>
#include <map>

using namespace std;

int V, E;
map<int, int> mp;


int parent[1005];
void init(){
	for(int i = 1; i <= V; i++) parent[i] = i;
}
int root(int i){
	if(parent[i] == i) return i;
	return parent[i] = root(parent[i]);
}
void unite(int i, int j){
	int root_i = root(i), root_j = root(j);
	if(root_i == root_j) return;
	parent[root_i] = root_j;
}

int main(void)
{
	cin >> V;
	init();
	
	char t;
	for(int i = 1; i <= V; i++){
		for(int j = 1; j <= V; j++){
			cin >> t;
			if(t == 'Y'){
				E++;
				unite(i, j);
			}
		}
	}
	E /= 2;
	
	int rem;
	if(V % 2){
		rem = V*(V-1)/2 - E;
		if(rem % 2) cout << "Taro" << endl;
		else cout << "Hanako" << endl;
		return 0;
	}
	
	for(int i = 1; i <= V; i++) mp[root(i)]++;
	int even = 0, odd = 0;
	for(auto it = mp.begin(); it != mp.end(); it++){
		if(it->second % 2) odd++;
		else even++;
	}
	
	if(odd == 0) goto EVEN;
	if(even == 0 && odd == 2) goto ODD;
	if(odd == 2 && even == 1){
		cout << "Taro" << endl;
		return 0;
	}
	
	EVEN:;
	rem = V*(V-1)/2 - E;
	if(rem % 2) cout << "Taro" << endl;
	else cout << "Hanako" << endl;
	return 0;
	
	ODD:;
	rem = V*(V-1)/2 - E + 1;
	if(rem % 2) cout << "Taro" << endl;
	else cout << "Hanako" << endl;
	return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int a,v,b,w;cin >> a >> v >> b >> w;
	int t;cin >> t;
	cout << (abs(a-b) <= t*(v-w)?"YES":"NO") << endl;
	return 0;
}

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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = 0;
  ll num = N / (A + B);
  ll b = N - num * (A + B);
  if(b < A) { ans = num * A + b; }
  else ans = num * A + A;

  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int L, R, D; cin >> L >> R>> D;
	cout << (R/D) - ((L-1)/D);
}


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

using namespace std;

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

    int num = 0;
    for(int i = 1; i < n - 1; i++)
    {
        if ((permutation[i - 1] < permutation[i] && permutation[i] < permutation[i + 1]) || (permutation [i - 1] > permutation[i] && permutation[i] > permutation[i + 1]))
        {
            num++;
        }
    }

    cout << num;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans=(make_divisors(m))
ans.sort()

for i in range(len(ans)):
    if ans[i]>m//n:
        print(ans[i-1])
        break
else:
    print(ans[-1])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    int FOOD[40] = {0};

    for (int i = 0; i < N; i++)
    {
        int num;
        cin >> num;
        for (int j = 0; j < num; j++)
        {
            int temp;
            cin >> temp;
            FOOD[temp - 1] += 1;
        }
    }
    int count = 0;
    for (int i = 0; i < M; i++)
    {
        if (FOOD[i] == N)
        {
            count++;
        }
    }

    cout << count;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using P = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
#define MOD 1000000007
#define INF 1000000000

vector<P> M;
VVI dp;
int solve(int start, int end) {
  if (dp[start][end] != INF)
    return dp[start][end];
  if (start + 2 == end)
    return dp[start][end] = dp[start][start+1] + dp[start+1][end] + M[start].first * M[start].second * M[start+1].second;
  int res = INF;
  for(int i = start; i + 1 != end; ++i) {
    res = min(res, solve(start, i + 1) + solve(i + 1, end) + M[start].first * M[i].second * M[end-1].second);
  }
  return dp[start][end] = res;
}
int main() {
  IN(N);
  dp.resize(N+1, VI(N+1, INF));

  REP(i, N) {
    IN(row);
    IN(column);
    M.push_back(make_pair(row, column));
    dp[i][i] = 0;
    dp[i][i+1] = 0;
  }
  OUT(solve(0, N));

  return 0;
}



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

int arr[200000] = { 0 };

int main()
{
	int n;
	long long result = 0;

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

	sort(arr, arr + n);

	int maxim = n - 1;
	result += arr[maxim];

	for (int i = 2; i < n; i++)
	{
		if (i % 2 == 0)
		{
			maxim--;
		}

		result += arr[maxim];
	}

	cout << result << endl;
}


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

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

int n, m;
int p[1010];

int main()
{
	while (cin >> n >> m, n){
		rep(i, n) cin >> p[i];
		sort(p, p + n, greater<int>());
		int res = 0;
		rep(i, n) res += p[i];
		for (int i = m - 1; i < n; i += m){
			res -= p[i];
		}
		cout << res << endl;
	}
}

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

int main() {
  string s, t; cin >> s >> t;
  bool answer = true;
  
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  
  for (int i = 0; i < min(s.size(), t.size()); i++) {
    if (s.at(i) < t.at(i)) {
      break;
    } else if (s.at(i) > t.at(i)) {
      answer = false;
      break;
    }
    if (i == min(s.size(), t.size()) - 1 && s.size() >= t.size()) answer = false;
  }
  
  if (answer) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int n; cin >> n;
    vector<pair<int, int> > A;
    rep(i,n){
        int x, y; cin >> x >> y;
        A.push_back(make_pair(x,y));
    }
    sort(A.begin(), A.end());
    rep(i,n){
        cout << A[i].first << " " << A[i].second << endl;
    }
}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;

void split(int n, string const & t, unordered_map<string, int> & f) {
    REP (x, 1 << n) {
        string a, b;
        REP (i, n) {
            (x & (1 << i) ? a : b) += t[i];
        }
        f[a + "/" + b] += 1;
    }
}

int main() {
    // input
    int n; cin >> n;
    string s; cin >> s;

    // solve
    string t1 = s.substr(0, n);
    string t2 = s.substr(n);
    reverse(ALL(t2));
    unordered_map<string, int> f, g;
    split(n, t1, f);
    split(n, t2, g);
    ll cnt = 0;
    for (auto const & it : f) {
        if (g.count(it.first)) {
            cnt += (ll)it.second * g[it.first];
        }
    }

    // output
    cout << cnt << endl;
    return 0;
}


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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;

const double PI = acos(-1);
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
	

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

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

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b%2 == 1) tmp = mulMod(tmp,a);
	return tmp;
}

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

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

//////////////////////////////////////////////

set < int > lst[15];

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	string str; cin >> str;
	FOR(i,n){
		int c = str[i] - '0';
		lst[c].insert(i);
	}
	set < int > :: iterator it1,it2,it3;
	int v1,v2;
	int ans = 0;
	FOR(i,10){
		it1 = lst[i].begin();
		if(it1 == lst[i].end()) continue;
		v1 = *it1;
		FOR(j,10){
			it2 = lst[j].lower_bound(v1+1);
			if(it2 == lst[j].end()) continue;
			v2 = *it2;
			FOR(k,10){
				it3 = lst[k].lower_bound(v2+1);
				if(it3 == lst[k].end()) continue;
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1664
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	int cnt = 0;
	for (int i = 100; i >= 1; --i) {
		if (a % i == 0 && b % i == 0) {
			cnt++;
		}
		if (cnt == k) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
from collections import Counter

n,x,y=map(int,input().split())

fr,to,w=[],[],[]

for i in range(n-1):
  fr.append(i)
  to.append(i+1)
  w.append(1)

fr.append(x-1)
to.append(y-1)
w.append(1)

g=csr_matrix((w, (fr, to)), shape=(n, n))
d=dijkstra(g,directed=False).astype(int)

#ans_l=np.bincount(d.ravel(), minlength=n)//2

ans_l=list(d.ravel())
c=Counter(ans_l)
for i in range(1,n):
  print(c[i]//2)

Measured memory_bytes: 203856
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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; }
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int dp[3001][3001];

int main(){
    string s, t;
    cin >> s >> t;
    rep(i, s.size()){
        rep(j, t.size()){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else {
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
    }

    string res = "";
    int i = s.size(), j = t.size();
    while(i > 0 && j > 0){
        if(dp[i][j] == dp[i-1][j]) i--;
        else if ( dp[i][j] == dp[i][j-1]) j--;
        else {
            res = s[i-1] + res;
            i--; j--;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 35456
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X; cin >> X;
    REP(i, 1, 1000) {
        int lower = 100 * i;
        int upper = 105 * i;
        if (lower <= X && X <= upper) {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	std::string input;
	cin >> input;
	int A{ atoi(input.c_str()) };
	cin >> input;
	int B{ atoi(input.c_str()) };
	int count = 0;
	for (int i = A; i <= B; ++i) {
		int d5 = i / 10000;
		int d4 = (i / 1000) % 10;
		int d2 = (i / 10) % 10;
		int d1 = i % 10;
		if (d5 == d1 && d4 == d2) {
			++count;
		}
	}
	cout << count;
}

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

int main(){
   char a[1000],b[1000],c[1000];
   int cnt=0;
   scanf("%s%s%s",a,b,c);
   int la=strlen(a);
   if(a[la-1]==b[0]) cnt++;
    la=strlen(b);
   if(b[la-1]==c[0])cnt++;
   if(cnt>>1) printf("YES");
   else       printf("NO");
}


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

typedef long long ll;

int main(){
    ll N, W;
    cin >> N >> W;
    ll W0;

    vector<ll> v(N);
    vector<ll> w(N);

    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
        if(i == 0){
            W0 = w[0];
            w[0] = 0;
        } else { 
            w[i] -= W0;
        }
    }

    ll dp[N][3*N+1][N+1];
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j <= 3*N; j++){
            for(ll k = 0; k <= N; k++){
                dp[i][j][k] = 0;
            }
        }
    }
    //dp[i][j][k] : iまで、補正済み重さj、個数kで最大価値

    // v0を使う場合
    dp[0][0][1] = (W0 <= W ? v[0] : 0 ) ;

    for(ll i = 0; i < N; i++){
        for(ll j = 0; j <= 3*N; j++){
            for(ll k = 0; k <= N; k++){
                // i+1を使う
                if(i+1 < N && j + w[i+1] <= 3*N && j + w[i+1] + W0 * (k+1) <= W  && k+1 <= N) {
                    dp[i+1][j + w[i+1]][k+1] = max(dp[i+1][j + w[i+1]][k+1], dp[i][j][k] + v[i+1]);
                }
                // i+1を使わない 
                if(i+1 < N){
                    dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
                }
            }
        }
    }


    ll ans = 0;
    for(int j=0; j<=3*N; j++){
        for(int k=0; k<=N; k++){
            ans = max(ans, dp[N-1][j][k]);
        }
    }
    cout << ans << endl;

}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

R limit[40010];

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

	vector<int> t(n), v(n);
	rep(i, n) cin >> t[i];
	rep(i, n) cin >> v[i];

	int total = 0;
	rep(i, n) total += t[i];

	rep(i, 40010) limit[i] = 1e10;

	int cur = 0;
	for (int i = 0; i <= 2 * total; ++i) {
		limit[i] = min<R>(0.5 * i, total - 0.5 * i);
	}

	rep(i, n) {
		for (int j = 2 * cur; j <= 2 * (cur + t[i]); ++j) {
			limit[j] = min<R>(limit[j], v[i]);
		}

		for (int j = 2 * cur; j >= 0; --j) {
			limit[j] = min<R>(limit[j], v[i] + 0.5 * (2*cur - j));
		}

		for (int j = 2 * (cur + t[i]); j <= 2 * total; ++j) {
			limit[j] = min<R>(limit[j], v[i] + 0.5 * (j - 2*(cur + t[i])));
		}
		cur += t[i];
	}

	R ans = 0.0;

	for (int i = 0; i < 2 * total; ++ i) {
		ans += 1.0 * (limit[i] + limit[i + 1]) / 4.0;
	}

	cout.precision(20);
	cout << fixed << ans << endl;

	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  K--;
  
  string S;
  cin >> S;
  
  if(S.at(K) == 'A')
    S.at(K) = 'a';
  if(S.at(K) == 'B')
    S.at(K) = 'b';
  if(S.at(K) == 'C')
    S.at(K) = 'c';

  cout << S << endl;
}


Measured memory_bytes: 256
s = input()
compress = []
i = 0
while i < len(s):
    if s[i:i+2] == 'BC':
        compress.append('D')
        i += 2
    else:
        compress.append(s[i])
        i += 1
ans = 0
count = 0
for x in compress:
    if x == 'A':
        count += 1
    elif x == 'D':
        ans += count
    else:
        count = 0
print(ans)

Measured memory_bytes: 5096
#include<stdio.h>
int main()
{
  char s[3];
  for(int i=0;i<3;i++)
    scanf("%s",&s[i]);
  
  if(s[0]==s[1]&&s[1]==s[2]){
    puts("No");
  }
  else {
    puts("Yes");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;


int main() {
	int n; cin >> n;
	vector<int> t(n + 2);
	vector<double> v(n + 2), va;
	for (int i = 1; i <= n; i++) cin >> t[i];
	for (int i = 1; i <= n; i++) cin >> v[i];
	for (int i = 1; i <= n; i++) t[i] += t[i - 1];
	for (int i = 0; i <= n; i++) t[i] *= 2;
	for (int i = 0; i <= t[n]; i++) {
		double s = i/2.;
		for (int j = 1; j <= n; j++) {
			if (t[j - 1] <= i && i <= t[j]) s = min(s, v[j]);
			else if (i < t[j - 1]) s = min(s, v[j] + abs(t[j - 1] - i)/2.);
			else if (t[j] < i) s = min(s, v[j] + abs(t[j] - i)/2.);
		}
		s = min(s, abs(t[n] - i) / 2.);
		va.push_back(s);
	}

	double ans = 0;
	for (int i = 0; i < (int)va.size() - 1; i++) {
		ans += 0.5*(va[i + 1] + va[i]) / 2.;
	}
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

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

int main() {
	int n,l,r;
	int sum=0;
	cin >> n;
	for(int i =0;i<n;i++){
		scanf("%d %d",&l,&r);
		sum +=  r-l+1;
	}
	cout << sum;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits>
#include <cstdint>

int main() {
  std::vector<std::int64_t> X(2), Y(2);
  std::cin >> X[0] >> X[1] >> Y[0] >> Y[1];
  std::int64_t max = std::numeric_limits<std::int64_t>::min();
  for (const auto x : X) {
    for (const auto y : Y) {
      max = std::max(max, x * y);
    }
  }
  std::cout << max << std::endl;
  return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)

int main()
{
    int n,l;
    cin>>n>>l;
    int ans=(l-1)*n+n*(n+1)/2;
    if(l>0)cout<<ans-l<<endl;
    else if(l+n-1<0)cout<<ans-(l+n-1)<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 764
// デバッグ実行：Ctrl+F5

using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        int n = int.Parse(line);
        line = Console.ReadLine();
        String[] words = line.Split(' ');
        Dictionary<string, int> OddNum = new Dictionary<string, int>();
        Dictionary<string, int> EvenNum = new Dictionary<string, int>();
        int OddMax = 0;
        int OddNext = 0;
        string OddMaxString = "";
        int EvenMax = 0;
        int EvenNext = 0;
        string EvenMaxString = "";
        //奇数
        for (int i = 0; i < n; i+=2)
        {
            if (OddNum.ContainsKey(words[i]))
            {
                OddNum[words[i]] += 1;
            }
            else
            {
                OddNum.Add(words[i], 1);
            }
            if (OddMax <= OddNum[words[i]])
            {
                OddNext = OddMax;
                OddMax = OddNum[words[i]];
                OddMaxString = words[i];
            }
        }
        // 偶数
        for (int i = 1; i < n; i += 2)
        {
            if (EvenNum.ContainsKey(words[i]))
            {
                EvenNum[words[i]] += 1;
            }
            else
            {
                EvenNum.Add(words[i], 1);
            }
            if (EvenMax <= EvenNum[words[i]])
            {
                EvenNext = EvenMax;
                EvenMax = EvenNum[words[i]];
                EvenMaxString = words[i];
            }
        }
        // 数字の種類が1種類の場合は例外
        if (OddMax == n/2 && EvenMax == n / 2 && words[0] == words[1])
        {
            Console.WriteLine(n / 2);
        }
        else
        {
            // 最大値どうしが同じ場合はマズいのでずらさなきゃいけない
            if (EvenMaxString == OddMaxString)
            {
                if (EvenMax > OddMax)
                {
                    // 偶数優先
                    Console.WriteLine(n - EvenMax - OddNext);
                }
                else if (EvenMax < OddMax)
                {
                    // 奇数優先
                    Console.WriteLine(n - OddMax - EvenNext);
                }
                else
                {
                    // Nextを見なくちゃいけないパターン
                    if (EvenNext > OddNext)
                    {
                        Console.WriteLine(n - OddMax - EvenNext);
                    }
                    else
                    {
                        Console.WriteLine(n - EvenMax - OddNext);
                    }
                }
            }
            else
            {
                Console.WriteLine(n - EvenMax - OddMax);
            }
        }
    }
}

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

int main() {
   int N, T, i, c, t, ans_c = 1005, ans_t = 0;
   cin >> N >> T;

   for (i = 0; i < N; i++) {
      cin >> c >> t;
      if (t <= T && c <= ans_c) {
         ans_c = c;
      }
   }
   if (ans_c == 1005) { 
      cout << "TLE" << endl;
      return 0;
   } 
   cout << ans_c << endl;

   return 0;
}


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

const int mod = 1e9+7;
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n;
    cin>>n;
    int a[n];
    for (int i=0; i<n; i++) cin>>a[i];
    int pre[n];
    pre[0] = a[0];
    for (int i=1; i<n; i++){
        pre[i] = (a[i]+pre[i-1])%mod;
    }
    int ans = 0;
    for (int i=n-1; i>0; i--){
        int prev = pre[i-1];
        int here = (prev*a[i])%mod;
        ans = (ans + here)%mod;
    }
    cout<<ans<<endl;

    return 0;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}



int check(int n) {

	int temp = n + 9;

	temp = temp / 10;
	return temp * 10;



}

bool comp(int a, int b) {


	return a % 10 > b % 10;

}

int main() {
	int i, n, m, k, c = 0;
	c_p_c();
	ll r ,D, x200;
	cin>>r>>D>>x200;



	for (int i = 0; i < 10; ++i)
	{
		/* code */
		ll ans = r*x200-D;
		cout<<ans<<endl;
		x200=ans;
	}

	return 0;
}



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

int main() {
	int n;
	cin >> n;
	vector<int>v(n), c(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += max(0, v[i] - c[i]);
	}
	cout << ans << endl;


	return 0;
}

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

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	double a[n];
	for(int i=0;i<n;i++)
	{
		cin >> a[i];		
	}	
	int k = n-1;
	while(k--)
	{
		sort(a, a+n);
		a[0] = (a[0] + a[1]) / 2.0;
		n = n-1;
		for(int i=1;i<n;i++)
			 a[i] = a[i+1];
	}
	cout << a[0] << endl;
} 

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0; i < n-1; i++) {
			b[i] = sc.nextInt();
		}
		List<Integer> a = new ArrayList<>(Arrays.asList(100001));
		int ans = 0;
		
		for(int i = 0; i < n-1; i++) {
			if(a.get(i) > b[i]) {
				a.set(i, b[i]);
			}
			a.add(i+1,b[i]);
		}
		
		for(int k : a) {
			ans += k;
		}
		
		pw.print(ans);
		pw.close();
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}

Measured memory_bytes: 22996
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC168
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_A();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var n = Ex.Read;

            int i = n.LastOrDefault() - '0';
            if (i == 2 || i == 4 || i == 5 || i == 7 || i == 9) "hon".Cw();
            else if (i == 3) "bon".Cw();
            else "pon".Cw();
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
        public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
        public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 18332
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    def digitsum(n):
        res = 0
        while n:
            res += n%10
            n //= 10
        return res
    n = I()
    ans = float("inf")
    for a in range(1,(n>>1)+1):
        b = n-a
        m = digitsum(a)+digitsum(b)
        if m < ans:
            ans = m
    print(ans)
    return

#B
def B():
    def comb(a,b):
        return fact[a]*inv_fact[b]*inv_fact[a-b]%mod
    mod = 998244353
    n,a,b,k = LI()
    fact = [1]*(n+1)
    for i in range(1,n+1):
        fact[i] = fact[i-1]*i%mod
    inv_fact = [None]*(n+1)
    inv_fact[n] = pow(fact[n],mod-2,mod)
    for i in range(n)[::-1]:
        inv_fact[i] = inv_fact[i+1]*(i+1)%mod

    ans = 0
    for x in range(n+1):
        if (k-a*x)%b == 0 and k >= a*x and k-a*x <= n*b:
            y = (k-a*x)//b
            ans += comb(n,x)*comb(n,y)%mod
        ans %= mod
    print(ans)

#C
def C():
    n = I()
    d = LIR(n)
    x = [None for i in range(n)]
    for i in range(n):
        if d[i][0]*d[i][1] <= 0:
            x[i] = 0
        else:
            if d[i][1] < 0:
                x[i] = d[i][1]
            else:
                x[i] = d[i][0]
    x.sort(key = lambda x:x)
    l = 0
    r = n-1
    ans = abs(x[l])
    k = 1
    while r-l > 0:
        ans += x[r]-x[l]
        if k:
            k = 0
            l += 1
        else:
            k = 1
            r -= 1
    ans += abs(x[r])
    l = 0
    r = n-1
    ans2 = abs(x[r-1])
    k = 0
    while r-l > 0:
        ans2 += x[r]-x[l]
        if k:
            k = 0
            l += 1
        else:
            k = 1
            r -= 1
    ans2 += abs(x[r])
    print(max(ans,ans2))
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()


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

#define endl "\n"
#define si(a) scanf("%d ",&a);
#define si2(a,b) scanf("%d %d ",&a,&b);
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sll(a) scanf("%lld ",&a);
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sf(a) scanf("%f ",&a);
#define sd(a) scanf("%lf ",&a);
#define sc(a) scanf("%c ",&a);
#define ss(a) scanf("%s ",a);
#define sf2(a,b) scanf("%f %f ",&a,&b);
#define sd2(a,b) scanf("%lf %lf ",&a,&b);
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<n;i++)
#define forq(i,q,n) for(int i=q;i<n;i++)
#define form(i,n) for(int i=n;i>=0;i--)
#define forp(i,q,n) for(int i=q;i>=n;i--)
#define fi first
#define se second
#define INF 1000000010
#define MOD 1000000007
#define MAXN
#define LL long long int


using namespace std;

long double a, b;

void init(){
	cin >> a >> b;
	if(a > b) {
		cout << "GREATER" << '\n';
	}
	if(a < b) {
		cout << "LESS" << '\n';
	}
	if(a == b) {
		cout << "EQUAL" << '\n';
	}
}

int main(){
	
	init();
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.next();
        String s2[] = s1.split("");
        int count = 0;
      
        for(int i =0; i < s2.length; i++){
            if(s2[i].equals("1")){
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 35736
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s:String,
    }
    if s == "AAA" || s == "BBB" {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>


int main(){
    long x;
    std::cin >> x;
    if(x==0){
        std::cout << 1 << std::endl;
    }else{
        std::cout << 0 << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  VI a(N);
  INPUT(a);
  VB dp(K+1);
  REP(i, K+1)
  {
    if (i == 0) dp[i] = false;
    else
    {
      REPx(x, a)
      {
        if (i-x >= 0 && !dp[i-x])
        {
            dp[i] = true;
            break;
        }
      }
    }
  }
  if (dp[K]) cout << "First" << endl;
  else cout << "Second" << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import deque
s= input()
q= int(input())
inv = False
head = deque()
tail = deque()
for i in range(q):
    p = input()
    if p[0]=='1':
        if inv:inv=False
        else:inv=True
    elif p[0]=='2':
        _,f,c= p.split()
        if f=='1':
            if inv:tail.append(c)
            else:head.appendleft(c)
        elif f=='2':
            if inv:head.appendleft(c)
            else:tail.append(c)
news = ''.join(head) + s + ''.join(tail)
if inv:print(news[::-1])
else:print(news)

Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
#define ep emplace_back
int main(){
	int n;
	scanf("%d", &n);
	int a[n], b[n], x = -1, c = 0, p = 0;
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i++) scanf("%d", &b[i]);
	reverse(b, b + n);
	for (int i = 0; i < n; i++) if (a[i] == b[i]) x = a[i], c++;
	if (x == -1){
		printf("Yes\n");
		for (int i = 0; i < n; i++) printf("%d ", b[i]);
		printf("\n");
		return 0;
	}
	vector<int> v;
	for (int i = 0; i < n; i++) if (a[i] != x && b[i] != x) v.ep(i);
	if (c > v.size()){
		printf("No\n");
		return 0;
	}
	for (int i = 0; i < n; i++){
		if (a[i] == b[i]) swap(b[i], b[v[p++]]);
	}
	printf("Yes\n");
	for (int i = 0; i < n; i++) printf("%d ", b[i]);
	printf("\n");
}

Measured memory_bytes: 5888
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[2][30], isLeaf[30];
using Graph = vector< vector< pair<int, int> > >;

int solve(Graph &G, int mode, int cur, int par=-1) {
    if(dp[mode][cur] >= 0) return dp[mode][cur];

    int child = 0;
    dp[mode][cur] = (mode ? INF : 0);
    for(auto e : G[cur]) {
        int to, cost; tie(to, cost) = e;
        if(to == par) continue;

        child++;
        int val0 = solve(G, 0, to, cur);
        int val1 = solve(G, 1, to, cur);
        if(isLeaf[to]) cost = 0;
        
        if(mode == 0) {
            dp[mode][cur] += val0 + 2 * cost;
        }
        if(mode == 1) {
            int curVal = solve(G, 0, cur, par);
            chmin(dp[mode][cur], curVal - cost - val0 + val1);
        }
    }
    isLeaf[cur] = (child == 0);
    if(isLeaf[cur] && mode == 1) dp[mode][cur] = 0;
    return dp[mode][cur];
}
 
signed main() {
    int N;
    while(cin >> N, N) {
        memset(dp, -1, sizeof(dp));
        memset(isLeaf, 0, sizeof(isLeaf));

        Graph G(N);
        for(int i=0; i<N-1; i++) {
            int a, b, t; cin >> a >> b >> t;
            a--; b--;
            G[a].push_back(make_pair(b, t));
            G[b].push_back(make_pair(a, t));
        }

        cout << solve(G, 1, 0) << endl;
    }
    return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const ll maxn=1000001,mod=1e9+7;

int main(){
sync

string a,b,c;
int n;
cin>>n>>a>>b>>c;
string change;
forn(i,n){
    map<char,int> hehe;
    hehe[a[i]]++;
    hehe[b[i]]++;
    hehe[c[i]]++;
    char c;int cnt=-1;
    for(auto it:hehe){
        if(it.se>cnt){
            cnt=it.se;
            c=it.fi;
        }
    }
    change+=c;
}
int ans=0;
forn(i,n){
    if(a[i]!=change[i]){
        ans++;
    }
    if(b[i]!=change[i]){
        ans++;
    }
    if(c[i]!=change[i]){
        ans++;
    }
}
cout<<ans;
return 0;
}

Measured memory_bytes: 256