akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll n, k, x;
  cin >> n >> k;
  vector<ll> x_posi;
  vector<ll> x_nega;
  for(int i = 0; i < n; ++i)
  {
    cin >> x;
    (x < 0 ? x_nega : x_posi).emplace_back(x);
  }
  reverse(x_nega.begin(), x_nega.end());

  ll ans = 1LL << 60;
  int ps = x_posi.size();
  int ns = x_nega.size();
  for(int i = 0; i <= k; ++i)
  {
    int pi = i - 1;
    int ni = k - i - 1;
    if (ps <= pi) continue;
    if (ns <= ni) continue;

    ll cost = 0;
    if (ni < 0) cost = x_posi[pi]; 
    else if (pi < 0) cost = -x_nega[ni];
    else cost = min(x_posi[pi] * 2 - x_nega[ni], x_posi[pi] - x_nega[ni] * 2);

    ans = min(ans, cost);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4552
// D - Redistribution
#include <bits/stdc++.h>
using namespace std;

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

	int S; cin>>S;
	int MOD = 1e9 + 7;
	int b3 = 1, b2 = 0, now = 0; // now == b1
	while(S-- > 2){ // S-2>0 -> S>2
		int b1 = now;
		now = (b1 + b3) % MOD;
		b3 = b2; b2 = b1;
	}
	cout<< now <<endl;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c; cin>>a>>b>>c;
    cout << (a-b)+1 << ednl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = {1, 0, -1, 0}, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	ll from, to, cost;
};

int v[10000005]={0};

int main() {
	int n;
    cin >> n;
    for(int  i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        v[a+b]++;
    }
    for(int i = 0; i < 10000000; i++){
        int num = v[i]/2;
        v[i] -= num * 2;
        v[i+1] += num;
    }
    for(int i = 0; i < 10000000; i++){
        if(v[i] > 0){
            cout << i <<" " <<v[i]-1 << endl;
        }
    }
	return 0;
}


Measured memory_bytes: 42176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			String str = sc.nextLine();
			str = sc.nextLine();
			char[] arr = str.toCharArray();

			int first = 0;
			int max = 0;
			for (char c : arr) {
				if (c == ')') first++;
				if (c == '(') first--;
				if (max < first) {
					max = first;
				}
			}
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < max; i++) {
				sb.append("(");
			}
			sb.append(str);
			str = sb.toString();
			arr = str.toCharArray();

			int countL = 0;
			int countR = 0;
			for (char c : arr) {
				if (c == ')') countR++;
				if (c == '(') countL++;
			}
			sb = new StringBuilder();
			if (countL < countR) {
				for (int i = 0; i < countR - countL; i++) {
					sb.append("(");
				}
			}
			sb.append(str);
			if (countR < countL) {
				for (int i = 0; i < countL - countR; i++) {
					sb.append(")");
				}
			}
			System.out.println(sb);


		}
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    char a[2], b[2];
    
    scanf("%s%s", a, b);
    
    if (a[0]<b[0]) {
        printf("<");
    } else if (a[0]>b[0]) {
        printf(">");
    } else {
        printf("=");
    }
    
    return 0;
}



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

typedef long long ll;

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> H(N);
    for(int i=0; i<N; i++) cin>>H[i];
    vector<vector<int>> G(N);

    for(int i=0; i<M; i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].push_back(H[b]);
        G[b].push_back(H[a]);
    }

    for(int i=0; i<N; i++) sort(G[i].begin(),G[i].end());

    int ans = 0;
    
    for(int i=0; i<N; i++){
        if(G[i].size() == 0){
            ans++;
            continue;
        }
        auto idx = lower_bound(G[i].begin(),G[i].end(),H[i]);
        int len = (G[i].end() - idx);
        if(len == 0) ans++;
    }

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

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

int main()
{
    int a, b, c, d;
    cin  >> a >> b;
    if (a == b)
        cout << "Draw" << endl;
    else if (a == 1 || (b != 1 && a > b))
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;

    return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int di2[] = {1, 1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1};
const int dj2[] = {1, -1, 1, -1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 2};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> l(n);
  rep(i, n) cin >> l[i];
  sort(ALL(l));
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = i+1; j < n; ++j) {
      for(int k = j+1; k < n; ++k) {
        if(l[i] == l[j] || l[j] == l[k]) continue;
        if(l[k] < l[i]+l[j]) ++ans;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
using namespace std;
struct ss{
	int rank;
    int p;
    int y;
}a[100005];
int cmp(ss x,ss y){
    if(x.p!=y.p) return x.p<y.p;
    else return x.y<y.y;
}
int main()
{
    int n ,m;
    scanf("%d%d",&n,&m);
    int b[100005];
    for(int i=0;i<m;i++){
    	a[i].rank=i;
        scanf("%d%d",&a[i].p,&a[i].y); 	
        b[i]=a[i].p;
	}
    sort(a,a+m,cmp);
    int f=a[0].p,flag=1;
    int x[100005];
    
    for(int i=0;i<m;i++){
    	if(a[i].p!=f) {flag=1;f=a[i].p;}
    	x[a[i].rank]=flag++;
	}
    // for(int i=0;i<m;i++)
    //    cout<< a[i].rank<<" "<<a[i].p<<" " <<a[i].y<<endl;
    for(int i=0;i<m;i++)
        printf("%06d%06d\n",b[i],x[i]);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }




int main() {
    cout << std::setprecision(30);
    double n;
    double x[8],y[8];
    cin >> n;
    FOR(i,0,n-1){
        cin >> x[i] >> y[i];
    }

    double dis = 0;

    FOR(i,0,n-1){
        FOR(j,0,n-1){
            if(i==j) continue;
            dis += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }

    double divnum = 1;
    FOR(i,1,n) divnum *= (double)i;

    cout << dis / n << endl;
    // cout << dis/7641.9817824387 << endl;

}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

alph = {}
index = {}
for i, a in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
    alph[a] = i
    index[i] = a


N = int(input())
S = str(input())

ans = ""
for s in S:
    ans += index[(alph[s] + N) % 26]
print(ans)

Measured memory_bytes: 40556
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    string s, S = "keyence";
    cin >> s;
    
    string tmp;
    bool flag = false;
    for (int i = 0; i < s.length(); i++) {
        for (int j = 0; i+j < s.length(); j++) {
            tmp = s.substr(0, i) + s.substr(i+j, s.length()-(i+j));
            // cout << tmp << endl;
            if (tmp == S) {
                flag = true;
            }
        }
    }
    if (flag) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
int H, N;


int main(void) {
    scanf("%d %d", &H, &N);
    rep(i, 0, N) {
        int A;
        scanf("%d", &A);
        H -= A;
    }

    if (H <= 0) puts("Yes");
    else puts("No");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
int main(){
  int a,b;
  cin >> a >> b;
  vector<vector<int> >ab(a+1,vector<int>(b+1,0));
  vector<int> w(a,0),v(a,0);
  for(int i = 0; i < a;i++){
    cin >> v[i] >> w[i];
  }
  for(int i = 1; i <= a; i++){
    for(int j = 0; j <= b; j++){
      if(w[i-1] > j){
	ab[i][j] = ab[i-1][j];
      }else{
	ab[i][j] = max(ab[i-1][j],ab[i-1][j-w[i-1]]+v[i-1]);
      }
    }
  }
  
  cout << ab[a][b] << endl;
}



Measured memory_bytes: 6772
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int F[50];
int fibonacchi(int n) {
    if (n == 0 || n == 1)
        return F[n] = 1;
    if (F[n] != -1)
        return F[n];
    else
        return F[n] = fibonacchi(n - 1) + fibonacchi(n - 2);
}

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

    int N;
    cin >> N;
    memset(F, -1, sizeof(F));
    cout << fibonacchi(N) << endl;

    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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(){
    ll t1,t2,a1,a2,b1,b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    a1=a1*t1;
    a2=a2*t2;
    b1=b1*t1;
    b2=b2*t2;
    a2+=a1;
    b2+=b1;
    if(a2==b2){
        cout << "infinity" << endl;
        return 0;
    }
    if(a2>b2){
        swap(a2,b2);
        swap(a1,b1);
    }
    if(b1>a1){
        cout << 0 << endl;
        return 0;
    }
    else if(b1<a1){
        ll c=a1-b1;
        ll d=b2-a2;
        if(c%d==0){
            cout << ((c+d-1)/d)*2 << endl;
        }
        else{
            cout << ((c+d-1)/d)*2 - 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int main() {
	int x;
	cin >> x;
	cout << (x >= 30 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3120
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

vvint vv;
vll A;
bool ok = true;

ll dfs(int x, int p){
	if(vv[x].size()==1) return A[x];
	vll tmp;
	ll sum = 0;
	for(int y: vv[x]){
		if(y == p) continue;
		tmp.PB(dfs(y, x));
		sum += tmp.back();
	}
	if(tmp.size()==1){
		if(tmp[0] != A[x]) ok=false;
		return A[x];
	}
	sort(ALL(tmp));
	ll a = sum - A[x];
	if(a<0 || A[x]<a) ok=false;
	if(sum-tmp.back()<a) ok=false;
	return A[x]-a;
}

bool mainmain(){
	int n;
	cin>>n;
	vv = vvint(n);
	A = vll(n);
	rep(i,n) cin>>A[i];
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		vv[a].PB(b);
		vv[b].PB(a);
	}
	if(n==2){
		return A[0]==A[1];
	}
	int root;
	rep(i,n){
		if(vv[i].size()>1){
			root = i;
			break;
		}
	}
	if(dfs(root,-1)){
		ok = false;
	}
	return ok;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    cout<<(mainmain()?"YES":"NO")<<endl;
}

Measured memory_bytes: 15872
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        for (int i = 0; i < n; i++) p[i] = sc.nextInt();
        for (int i = 0; i < n; i++) q[i] = sc.nextInt();
        int a = func(p);
        int b = func(q);
        System.out.println(Math.abs(a - b));
    }
    public static int func(int[] p) {
        int ret = 0;
        int n = p.length;
        boolean[] used = new boolean[n];
        for (int i = 0; i < n; i++) {
            int cnt = 0;
            for (int j = 1; j < p[i]; j++) {
                if (!used[j - 1]) cnt++;
            }
            ret += cnt * frac(n - 1 - i);
            used[p[i] - 1] = true;
        }
        return ret;
    }
    public static int frac(int x) {
        if (x == 0) return 1;
        return x * frac(x - 1);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(){
  int i,j,s[1000003],n,q,k=0,t;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t);
    for(j=0;j<n;j++){
      if(s[j]==t){
	k++;
	break;
      }
    }
  }
  printf("%d\n",k);
  return 0;
}

Measured memory_bytes: 3076
#include<stdio.h>
int main()
{
	int n, m, x;
	scanf("%d %d %d", &n, &m, &x);
	int c[20], a[20][20];
	int i, j, k, l;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &c[i]);
		for (j = 0; j < m; j++)
			scanf("%d", &a[i][j]);
	}
	int max = 1;
	for (i = 0; i < n; i++)
		max *= 2;
	int b[20];
	int res, ans = -1;
	for (k = 0; k < max; k++)
	{
		for (i = 0; i < m; i++)
			b[i] = 0;
		l = k;
		res = 0;
		for (i = 0; i < n; i++)
		{
			if (l % 2 > 0)
			{
				res += c[i];
				for (j = 0; j < m; j++)
					b[j] += a[i][j];
			}
			l /= 2;
		}
		if (res == 1067)
		{
			res++;
			res--;
		}
		for (i = 0; i < m; i++)
			if (b[i] < x)
				res = -1;
		if (res >= 0)
		{
			if (ans<0 || ans>res)
				ans = res;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500;
int n,m,q;
int dp[maxn+10][maxn+10];
int main()
{
    while(cin>>n>>m>>q)
    {
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=m;i++)
        {
            int u,v;
            cin>>u>>v;
            dp[u][v]++;
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                dp[i][j]+=dp[i][j-1];
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                dp[i][j]+=dp[i-1][j];
            }
        }
        for(int i=1;i<=q;i++)
        {
            int u,v;
            cin>>u>>v;
            printf("%d\n",dp[v][v]-dp[u-1][v]-dp[v][u-1]+dp[u-1][u-1]);
        }
    }
    return 0;
}


Measured memory_bytes: 1920
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    s = input()
    a = 0
    b = 0
    c = 0
    for e in s:
        if e == 'a':
            a += 1
        elif e == 'b':
            b += 1
        else:
            c += 1
    if abs(a - b) < 2 and abs(b - c) < 2 and abs(a - c) < 2:
        print("YES")
    else:
        print("NO")
        


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

abc

"""


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	int res = max((c-(a-b)), 0);
	pv(res)
	return(0);
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
count = 0
q = []

for i in range(1, n-1):
  q = [p[i-1], p[i], p[i+1]]
  if max(q) != p[i] and min(q) != p[i]:
    count += 1

print(count)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
  
 
A2nums = [0] * N
for i in range(N):
  while True:
    if A[i] % 2 == 0:
      A2nums[i] += 1
      A[i] /= 2
    else: 
      break    
 
print(min(A2nums))

Measured memory_bytes: 3060
#include <stdio.h>
   
int main()
{
   
  int a, b, r, tmp;
   
  scanf("%d %d",&a,&b);
   
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
   
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
   
  printf("%d\n", b);
   
  return 0;
}

Measured memory_bytes: 1828
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] count = new int[n + 1];
        int ans = 0;
        for (int i = 1; i <= n; i += 2) {
            for (int j = 1; j <= i; j++) {
                if (i % j == 0)
                    count[i]++;
            }
        }
        for (int i = 1; i <= n; i++) {
            if (count[i] == 8)
                ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
N = int(input())
A = list()
for n in range(N):
	A.append(list(map(int, input().split())))
dp = [[-1 for i in range(3)] for j in range(N)]
dp[0] = [A[0][0], A[0][1], A[0][2]]
for i in range(1, N):
	dp[i][0] = max(dp[i-1][1] + A[i][0], dp[i-1][2] + A[i][0])
	dp[i][1] = max(dp[i-1][0] + A[i][1], dp[i-1][2] + A[i][1])
	dp[i][2] = max(dp[i-1][0] + A[i][2], dp[i-1][1] + A[i][2])
# print(dp)
print(max(dp[N-1][0], dp[N-1][1], dp[N-1][2]))

Measured memory_bytes: 76760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

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

    vector<int> a(n);
    int i;
    REP(i, n) cin >> a[i];

    bool ng = false;
    REP(i, n) {
        if ( a[i] % 2 != 0 ) continue;
        if ( a[i] % 3 != 0 && a[i] % 5 != 0 ) ng = true;
    }

    if ( ng ) cout << "DENIED" << endl;
    else      cout << "APPROVED" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    double h;
    while(cin >> n){
        int ans[6] = {0};
        rep(i,n){
            cin >> h;
            if(h < 165)
                ans[0]++;
            else if(h >= 165 && h < 170)
                ans[1]++;
            else if(h >= 170 && h < 175)
                ans[2]++;
            else if(h >= 175 && h < 180)
                ans[3]++;
            else if(h >= 180 && h < 185)
                ans[4]++;
            else if(h >= 185)
                ans[5]++;
        }
        rep(i,6){
            cout << i + 1 << ":";
            rep(j,ans[i]){
                cout << '*';
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 1232
MOD = 10 ** 9 + 7

class ModCombination
  attr_reader :fac, :mod

  def initialize(n, mod: 10 ** 9 + 7)
    @mod = mod
    @fac = [1, 1]

    (2..n).each do |i|
      @fac[i] = fac[i - 1] * i % mod
    end
  end

  def combination(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0

    fa = 1

    n.downto(n - k + 1) do |i|
      fa = (fa * i) % mod
    end

    (fa * fac[k].mod_inverse) % mod
  end
end

class Integer
  def mod_pow(n, mod = 10 ** 9 + 7)
    x = self
    res = 1

    while n > 0
      res = res * x % mod if n[0] == 1
      x = x * x % mod
      n >>= 1
    end

    res
  end

  def mod_inverse(mod = MOD)
    mod_pow(mod - 2, mod)
  end
end

N, A, B = gets.split.map(&:to_i)
mc = ModCombination.new([A, B].max)

puts (2.mod_pow(N) - mc.combination(N, A) - mc.combination(N, B) - 1) % MOD


Measured memory_bytes: 3528
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		final int h = sc.nextInt();
		final int w = sc.nextInt();

		List<String> aList = new ArrayList<>();

		for (int i = 0; i < h; i++) {
			aList.add("#" + sc.next() + "#");
		}

		sc.close();

		String wresult = String.join("", Collections.nCopies(w, "#"));

		wresult = wresult + "##";

		System.out.println(wresult);
		for (final String a : aList) {
			System.out.println(a);
		}
		System.out.println(wresult);

	}

}

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

using namespace std;

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

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
const ll MOD=1e9+7;

int main() {
    int h,w,k;
    cin>>h>>w>>k;
    if (w==1){
        cout<<1<<endl;
        return 0;
    }
    ll dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    dp[0][1]=1;
    for (int i=1;i<h+1;i++){
        for (int j=1;j<w+1;j++){
            for (int p=0;p<(1<<w-1);p++){
                bitset<8> s(p);
                int b=1;
                for (int l=0;l<w-1;l++){
                    if (s.test(l) && s.test(l+1)){
                        b=0;
                        break;
                    }
                }
                if (b==0){
                    continue;
                }
                if (j==1){
                    if (s.test(j-1)){
                        dp[i][j]+=dp[i-1][j+1];
                    }
                    else{
                        dp[i][j]+=dp[i-1][j];
                    }
                    dp[i][j]%=MOD;
                }
                else if (j==w){
                    if (s.test(w-2)){
                        dp[i][j]+=dp[i-1][j-1];
                    }
                    else{
                        dp[i][j]+=dp[i-1][j];
                    }
                    dp[i][j]%=MOD;
                }
                else{
                    if (s.test(j-2)){
                        dp[i][j]+=dp[i-1][j-1];
                    }
                    else if (s.test(j-1)){
                        dp[i][j]+=dp[i-1][j+1];
                    }
                    else{
                        dp[i][j]+=dp[i-1][j];
                    }
                    dp[i][j]%=MOD;
                }
            }
        }
    }
    cout<<dp[h][k]<<endl;
    

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] a){
    	int fa = 0;
    	int fb = 0;
    	Scanner scan = new Scanner(System.in);
    	while (scan.hasNext()){
    	fa = scan.nextInt();
    	fb = scan.nextInt();
    	int sum = fa + fb;
    	 System.out.println((int) Math.log10(sum) + 1);
    	}
    }
 }

Measured memory_bytes: 25988
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define ff first
#define ar array
#define ss second
#define ll long long int
#define mem(x) memset(x,0,sizeof(x))
#define setbits(x)  __builtin_popcount(x)
#define ull unsigned long long int
#define all(c) (c).begin(),(c).end()
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define db double
#define endl "\n"
#define  fbo(x) find_by_order(x)
#define  ook(x) order_of_key(x)
 
using namespace __gnu_pbds;
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair<ll,ll > iil;
typedef pair<ll,int> li;
typedef pair<int,int> ii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    os1;
typedef tree<int, null_type, greater<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    os2;

inline void fast()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
const ll pi=31;
const ll MOD[2] = {1187278649, 1149736019};//for double hashing
const ll mod=(ll)(1e9)+7;
ll pmod(ll x,ll n){
  ll r=1;
  while(n>0)
  {
    if(n&1LL)
      r=(r*x)%mod;
    x=(x*x)%mod;
    n=n/2;
    n%=mod;
  }
  return r;
}
ll pMod(ll x,ll n,ll mod)
{ ll r=1;
  while(n>0)
  {
    if(n&1LL)
      r=(r*x)%mod;
    x=(x*x)%mod;
    n=n/2;
    n%=mod;
  }
  return r;
 
}
 
//think recursively also;
ll dp[102][100002];
void solve()
{ 
  
  ll n,w;
  cin>>n>>w;
  ll wv[n+1][2];
  ll mx=0;
  for(int i=1;i<=n;i++)
  {
    cin>>wv[i][0]>>wv[i][1];
    mx+=wv[i][1];
  }  
  ll ans=0;
  for(int i=1;i<=n;i++)
  {for(int j=1;j<=w;j++)
  {
   
       if(j-wv[i][0]>=0)
       {
         dp[i][j]=max(dp[i][j],dp[i-1][j-wv[i][0]]+wv[i][1]);
       }
       
        dp[i][j]=max(dp[i][j],dp[i-1][j]);    
  }
  }
  cout<<dp[n][w]<<endl;
  //cout<<ans<<endl;
}
int main()
{
  fast();
   // int t;
   // cin>>t;
   // for(int casee=1;casee<=t;casee++)
  {//cout<<"Case #"<<casee<<": ";
    solve();
  }
 
 
 
}

Measured memory_bytes: 81660
import math

def koyaku(a,b,c):
    totyu=math.gcd(a,b)
    return math.gcd(totyu,c)

k=int(input())
ans=0
for a in range(1,k+1):
    for b in range(1,k+1):
        totyu=math.gcd(a,b)
        for c in range(1,k+1):
            ans+=math.gcd(totyu,c)

print(ans)

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>


using namespace std;
 
 
int main() {
	int N;
	cin >> N;
	vector<int> P(N);
	for(int i = 0; i < N; i++){
		int a;
		cin >> a;
		P[i] = a;		
	}
	
	int count = 0;
	int MA = 1000000000;
	for(int i = 0; i < N; i++){
		if(MA > P[i]) MA = P[i];
		
		if(MA >= P[i]) count ++;
		
		
	}
	
	cout << count << endl;
	
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define N 8
int C[N], dpos[2*N-1], dneg[2*N-1], r[N], B[N][N]; // 0:FREE 1:NOTFREE

void init(void){
    for(int i = 0; i < N; i++){
        C[i] = 0;
        r[i] = 0;
        for(int j = 0; j < N; j++){
            B[i][j] = 0;
        }
    }
    for(int i = 0; i < 2*N-1; i++){
        dpos[i] = 0;
        dneg[i] = 0;
    }
}

void printB(){
  int i, j;
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
        if(B[i][j] == 1){
            if(r[i] != j) return;
        }
    }
  }

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(r[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
  
}

void putQueen(int p){
  int i;

  if(p == N){
    printB();
    return ;
  }

  for(i = 0; i < N; i++){
    if(C[i] == 1 || dpos[p+i] == 1) continue;
    if(dneg[p-i+N-1] == 1) continue;
    r[p] = i; 
    C[i] = dpos[p+i] = dneg[p-i+N-1] = 1;

    putQueen(p+1);

    r[p] = C[i] = dpos[p+i] = dneg[p-i+N-1] = 0;
  }
}

int main(){
  int nm, i, p, q, j;

    init();

  scanf("%d", &nm);
  
  for(i = 0; i < nm; i++){
    scanf("%d%d", &p, &q);
    B[p][q] = 1;
  }

  putQueen(0);
  
  
     
  
  return 0;
}



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

typedef long long ll;

int main(){
  int A,B;
  cin >> A >> B;
  if(B == 1){
    cout << 0 <<endl;
    return 0;
  }
  if(A >= B){
    cout << 1 <<endl;
    return 0;
  }
  cout << ceil((double)(B-A)/(A-1))+1 <<endl;
}

Measured memory_bytes: 256
from sys import stdin

n, k = [int(x) for x in stdin.readline().rstrip().split()]
v = list(map(int, input().split()))

l = [ [(0, [])]*(k+1) for _ in range(k+1)]

left=0
right=0
for i in range(k+1):
  left=0
  for j in range(k+1):
    if i==0 and j==0:
        continue
#    if k <= (left+right):
    if len(v) < (i+j):
        break
    if k < (i+j):
        break
    if j==0:
      item = v[(n-1)-right]
      right +=1
      l[i][j] = (l[i-1][j][0]+item,l[i-1][j][1]+[item])
      continue
    item = v[left]
    left +=1
    l[i][j] = (l[i][j-1][0]+item,l[i][j-1][1]+[item])

#for i in range(k+1):
#  print(l[i])

ans = 0
for i in range(k+1):
  for j in range(k+1):
    if k < (i+j):
      break
    value = l[i][j][0]
    if ( k != (i+j)):
        itemlist = l[i][j][1]
        itemlist.sort()
        #print(itemlist)
        for ii in range (k-(i+j)):
           if len(itemlist) <= ii:
               break
           if 0 < itemlist[ii]:
               break
           value -= itemlist[ii]
        #print(i,j,value)
    ans = max(ans, value)

print(ans)


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

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

  for (int m = 13; m <= 1000; ++m) {
    if((int)(m*0.08) == a && (int)(m*0.10) == b) {
      std::cout << m << std::endl;
      return 0;
    }
  }
  std::cout << -1 << std::endl;
}


Measured memory_bytes: 3640
my $s=<>;chomp $s;
my @S = split(//,$s);
   $s=<>;chomp $s;
my @T = split(//,$s);


my $min = $#T+1; 
#print "fst $min\n";

for(my $i=0;$i<=($#S-$#T);$i++ ){
    my $count=0;
    
    
    for(my $j=0;$j<=$#T;$j++ ){
        if( $T[$j] ne $S[$i+$j]){
            $count++;
        }
    }
    if($min > $count){
        $min = $count;
    }
}

print "$min";

Measured memory_bytes: 4940
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int r,c; cin >> r >> c;
    int data[r+1][c+1]={};
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin >> data[i][j];
        }
    }
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            data[i][c]+=data[i][j];
            data[r][j]+=data[i][j];
        }
        data[r][c]+=data[i][c];
    }
    
    for(int i=0;i<r+1;i++){
        for(int j=0;j<c+1;j++){
            cout << data[i][j];
            if(j!=c){
                cout << " ";
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3092
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
        }
        System.out.println(gcd_list(A));
    }
    public long gcd(long x, long y) {
        if (y == 0) {
            return x;
        }
        return gcd(y, x % y);
    }
    public long gcd_list(long[] x) {
        long answer = 0;
        for (int i = 0; i < x.length; i++) {
            answer = gcd(x[i], answer);
        }
        return answer;
    }
}


Measured memory_bytes: 61996
from collections import Counter
s = input()
#sInt = int(s)
count = Counter(s)
num0 = count['0']
num1 = count['1']

diff = num0 - num1
if (diff == 0):
    ans = num0 * 2
elif (diff > 0):
    ans = num1 * 2
else:
    ans = num0 * 2


print(ans)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
//#pragma GCC optimize(2)
using namespace std;
//const double eps=1e-6;
//typedef complex<double>C;
//const double PI(acos(-1.0));
//for(int mask=i;mask>0;mask=(mask-1)&i)
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){int s=0;while(x){s+=BIT[x];x-=x&-x;}return s;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a,LL b){LL t=1;for(;b;b>>=1,a=a*a%M)b&1?t=t*a%M:0;return t;}
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//cout<<fixed<<setprecision(12)<<ans<<endl;
//__builtin_popcount(mask)
//isalnum() decimal digit or an uppercase or lowercase letter
const int N=1234567;
const int M=1e9+7;
int n;
int f(int x){
	int s=0;
	while(x)s+=x%10,x/=10;
	return s;
}
int main(){Accel
	cin>>n;
	int mx=1e9;
	FOR(i,1,n-1){
		int a=i,b=n-i;
		mx=min(f(a)+f(b),mx);
	}
	cout<<mx<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a;
  bool h, k;
  string s;
  in(s);
  a = s.size();
  while(true){
    k = false;
    rep(i, s.size() - a + 1){
      h = true;
      rep(j, a){
        if(s[i + j] != 'A' && s[i + j] != 'T' && s[i + j] != 'C' && s[i + j] != 'G')
          h = false;
      }
      if(h){
        k = true;
        break;
      }
    }
    if(k)
      break;
    a--;
    if(a == 0)
      break;
  }
  out(a);
  memi;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
#define W 0
#define B 1
 
int **m;
int *d;
int *p;
int *c;
 
void pr(int);
 
int main(){
  int n,i,j;
  int cost=0;
  scanf("%d",&n);
 
  c = malloc(n * sizeof(int));
  d = malloc(n * sizeof(int));
  p = malloc(n * sizeof(int));
 
  m = malloc(n * sizeof(int *));
  for(i=0; i<n; i++)
    m[i] = malloc(n * sizeof(int));
 
  for(i=0; i<n; i++)
    for(j=0; j<n; j++)
      m[i][j] = -1;
   
  for(i=0; i<n; i++)
    for(j=0; j<n; j++)
      scanf("%d",&m[i][j]);
 
  pr(n);
 
  for(i=0; i<n; i++)
    cost += d[i];
    
  printf("%d\n", cost);
 
  free(d);
  free(c);
  free(p);
  for(i=0; i<n; i++) free(m[i]);
  free(m);
 
  return 0;
   
}
 
 
void pr(int n){
  int mincost;
  int i,j,u;
 
  for(i=0; i<n; i++){
    d[i] = 2001;
    p[i] = -1;
    c[i] = W;
  }
 
  d[0] = 0;
 
  while(1){
    mincost = 2001;
 
    for(i=0; i<n; i++){
      if(c[i] != B && d[i] < mincost){
    mincost = d[i];
    u = i;
      }
    }
 
    if(mincost == 2001) break;
 
    c[u] = B;
 
    for(i=0; i<n; i++){
      if(c[i] != B && m[u][i] != -1 && m[u][i] < d[i]){
    d[i] = m[u][i];
    p[i] = u;
      }
    }
  }
}

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

int main(){
  int n;
  cin >> n;
  int p[n+1];
  for(int i = 1;i <= n;i++){
    cin >> p[i];
  }
  int kekka = 0;
  for(int i = 1;i < n;i++){
    if(i == p[i]){
      int tmp = p[i];
      p[i] = p[i+1];
      p[i+1] = tmp;
      kekka++;
    }
  }
  if(n == p[n]){
    kekka++;
  }
  cout << kekka << endl;
}   

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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int N = 1e5+5;

void init()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main()
{
	init();
	int n;
	string str;
	cin >> n >> str;

	if(n%2 == 1){
		cout << "No";
		return 0;
	}
	int haf = n/2;
	lp(i, haf){
		if(str[i] != str[i+haf]){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
map<int,int>Map;
struct Ask{
	int x,y;
}A[N];
int cmp(Ask x,Ask y){
	return x.y<y.y;
}
int flag[N],a[N],n;
signed main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&A[i].x),a[i]=A[i].x;
	for (int i=1;i<=n;i++)scanf("%d",&A[i].y);
	sort(a+1,a+n+1);sort(A+1,A+n+1,cmp);
	for (int i=1;i<=n;i++)
		if (a[i]>A[i].y){
			puts("No");
			return 0;
		}
	for (int i=1;i<n;i++)
		if (a[i+1]<=A[i].y){
			puts("Yes");
			return 0;
		}
	for (int i=1;i<=n;i++)Map[a[i]]=i;
	for (int i=1;i<=n;i++)a[i]=Map[A[i].x];
	int Flag=0,now=1;
	while (!Flag||now!=1){
		flag[now]=1;
		Flag=1;
		now=a[now];
	}
	for (int i=1;i<=n;i++)
		if (!flag[i]){
			puts("Yes");
			return 0;
		}
	puts("No");	
}

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

using namespace std;

int main() {
  int n; cin >> n;
  int l; cin >> l;
  vector <string> s(n);
  for(int i = 0; i < n; i++) {
    //cout << x << '\n';
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  string ans = "";
  for(int i = 0; i < n; i++) {
    ans += s[i];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[3010];
long long dp[3010][3010]; //[l, r)の要素が残っている状態から追加で得られる太郎君の最大得点
long long solve(int l, int r){
  if(l == r) return 0;
  if(dp[l][r] > 0) return dp[l][r];
  if((n - (r - l)) % 2 == 0) dp[l][r] = max(solve(l+1, r) + a[l], solve(l, r-1) + a[r-1]);
  else dp[l][r] = min(solve(l+1, r), solve(l, r-1));
  return dp[l][r];
}
int main(){
  cin >> n;
  for(int i=0; i<n; i++) cin >> a[i];
  solve(0, n);
  cout << dp[0][n] * 2 - accumulate(a, a+n, 0LL) << endl;
}

Measured memory_bytes: 49876
import numpy as np
import math

def comb(n, k):
    if k<0 or n<k:
        return 0
    return round(math.factorial(n)/math.factorial(k)/math.factorial(n-k))

N,P=[int(_) for _ in input().split()]
a=np.array([int(_) for _ in input().split()])


retVal=0
if P==0:
    retVal+=1
    
even=0
for i in range(N):
    if a[i]%2==0:
        even+=1
odd=N-even

for k in range(1, N+1):        
    i=(P+k)%2    
    while i<=min(even,k):
        retVal+=comb(even, i)*comb(odd,k-i)
        i+=2        
print(retVal)

Measured memory_bytes: 12408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100005
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int parent[MAX], count[MAX];

int Root(int x) {
  if (parent[x] == x) return x;
  return parent[x] = Root(parent[x]);
}

void Union(int x, int y) {
  int rx = Root(x);
  int ry = Root(y);
  parent[rx] = ry;
  if ( rx != ry ) count[ry] += count[rx]; 
}


int main(void) {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  int a[MAX], b[MAX], c[MAX], d[MAX];
  rep(i, 0, m) scanf("%d %d", &a[i], &b[i]);
  rep(i, 0, k) scanf("%d %d", &c[i], &d[i]);

  rep(i, 1, n+1) {
    parent[i] = i;
    count[i] = 1;
  }

  rep(i, 0, m) Union(a[i], b[i]);

  int friends[MAX] = {0};
  rep(i, 0, m) {
    friends[a[i]]++; friends[b[i]]++;
  }
  int block[MAX] = {0};
  rep(i, 0, k) {
    if (Root(c[i]) == Root(d[i])) {
      block[c[i]]++; block[d[i]]++;
    }
  }
  rep(i, 1, n+1) 
    printf("%d ", count[Root(i)] - friends[i]- block[i] - 1);
  return 0;
}


Measured memory_bytes: 4480
import java.io.*;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a <= b && a <= c){
            if(b<=c){
                System.out.printf("%d %d %d", a, b, c);
            }
            else{
                 System.out.printf("%d %d %d", a, c, b);
            }
        }
        else if(b<=c && b <= a){
            if(a<=c){
                System.out.printf("%d %d %d", b, a, c);
            }
            else{
                System.out.printf("%d %d %d", b, c, a);
            }
        }
        else{
            if(a<=b)
                System.out.printf("%d %d %d", c, a, b);
            else
                System.out.printf("%d %d %d", c, b, a);
        }
System.out.println();

        sc.close();
    }
}

Measured memory_bytes: 26412