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

int main(){
    int  A, B;

    //input
    cin >> A >> B;

    if(A <= 12 && A >= 6){
        cout << B / 2 << endl;
    }else if(A < 6){
        cout << 0 << endl;
    }else{
        cout << B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>

using namespace std;


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

		if (A <= 8 && B <= 8)cout <<"Yay!"<< endl;
		else cout << ":(" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, k, q, a[2010];
vector<int> vec;
int ans = INF;

signed main() {
	cin >> n >> k >> q;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		vec.push_back(a[i]);
	}
	sort(all(vec));
	for (int i = 0; i <= n - q; i++) {
		int cnt = 0, cnt2 = 0;
		priority_queue<int, vector<int>, greater<int>> que, que2;
		for (int j = 0; j < n; j++) {
			if (a[j] < vec[i]) {
				cnt = 0;
				while (!que.empty())que.pop();
			}
			else {
				cnt++;
				que.push(a[j]);
				if (k <= cnt) {
					cnt2++;
					que2.push(que.top());
					que.pop();
				}
			}
		}
		if (q <= cnt2) {
			int ma = 0;
			for (int j = 0; j < q; j++) {
				ma = max(ma, que2.top());
				que2.pop();
				
			}
			ans = min(ans, ma - vec[i]);
		}
	}
	cout << ans << endl;
}


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

int main(){
    string s;
    string t;
    cin >> s >> t;

    int min = t.size();
    for(int i=0; i<=s.size()-t.size(); i++){
        string ss = s.substr(i, t.size());
        int m = 0;
        for(int j=0; j<ss.size(); j++){
            if(ss[j]!=t[j]){
                m++;
            }
        }
        if(min>m)  min = m;
    }

    cout << min << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main{
  public static void main(String[] args){
  	Scanner scanner = new Scanner(System.in);
  	int K = scanner.nextInt();
  	int S = scanner.nextInt();
    
    int Z = K;
    int counter = 0;
    while(Z>=0){
      int Y = S-Z;
      if(Y>K){
        Y=K;
      }
      while(Y>=0){
        int X = S-Z-Y;
        if(K>=X && X>=0){
          counter++;
        }
        Y--;
      }
      Z--;
    }
  
  	System.out.println(counter);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>vi;
vector<ll> :: iterator vt;
ll arr[200009];
int main()
{
    ll n,t,x,mul=1,i,j,flag =0,maxi=LONG_LONG_MIN,mini=LONG_LONG_MAX,sum=0,c=0;
    map<char,ll>mp;
    map<char,ll> :: iterator mt;
    string s, ss;
    cin>>n>>x;
    for(i = 0 ;i<n ;i++)
    {
        cin>>t;
        vi.push_back(abs(x-t));
    }
    sum=__gcd(vi[0],vi[0]);
    for(i = 1 ;i<n ;i++)
    {
        sum=__gcd(vi[i],sum);
    }
    cout<<sum<<endl;
    return 0;
}


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

int main() {
  int N, L;
  cin >> N >> L;

  int apple_number;
  int min_abs = 1000;

  for (int i = 1; i <= N; i++) {
    int flavor = L + i - 1;
    if (abs(flavor) < min_abs) {
      min_abs = abs(flavor);
      apple_number = i;
    }
  }

  int total = 0;
  for (int i = 1; i <= N; i++) {
    if (i != apple_number) {
      int flavor = L + i - 1;
      total += flavor;
    }
  }

  cout << total << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, a;
	set<int> st;
	cin >> n;
	while (n--) {
		cin >> a;
		auto it = st.find(a);
		if (it == st.end()) {
			st.insert(a);
		}
		else {
			st.erase(it);
		}
	}

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

	return 0;
}

Measured memory_bytes: 4864
/// Author: Wang, Yen-Jen
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAX_N = 10 + 7;

int A[MAX_N];
ll dp[MAX_N][2];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++)
    scanf("%d", &A[i]);
  dp[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = A[i] - 1; j <= A[i] + 1; j++) {
      if (j & 1) {
        dp[i][0] += dp[i - 1][0];
        dp[i][1] += dp[i - 1][1];
      }
      else {
        dp[i][1] += dp[i - 1][0] + dp[i - 1][1];
      }
    }
  }
  printf("%lld\n", dp[N][1]);
  return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/arc066/tasks/arc066_b
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

constexpr int mod = 1e9+7;
map<LL,LL> ret;
LL f(LL k){
    if(k==0)return 0;
    if(k==1)return 1;
    if(ret.count(k))return ret[k];
    if(k%2==1){
        return ret[k]=(f(k/2)*2%mod+f(k/2+1))%mod;
    }
    else{
        return ret[k]=(f(k/2)*2%mod+f(k/2-1))%mod;
    }
}
int main(){
    LL k;
    cin>>k;
    cout<<f(k+1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	ll A,B; cin>>A>>B;
	ll ans = 0;

	//1st-ditit
	ll hd = (A+3LL)/4*4;
	ll tl = B/4*4;
	ll fst = -1;
	for(ll i = A; i<=hd; ++i){ if(i%2 == 1)fst *= -1;}
	for(ll i = B; i>=tl; --i){ if(i%2 == 1)fst *= -1;}
	if(fst == 1) ++ans;

	//others
	for(ll bit = 1; pow(2,bit-1)<=B; ++bit){
		ll digit = pow(2,bit);
		ll h = (A+digit-1LL)/digit*digit;
		ll t = B/digit*digit;
		ll e_ans = 0;
		if(h / digit % 2 == 0){
			e_ans += h-A;
		}
		if(t / digit % 2 == 1){
			e_ans += B-t+1LL;
		}
		// printf("[digit, head, tail e_ans] -> [%lld, %lld, %lld, %lld]\n", digit, h, t, e_ans);
		if(e_ans % 2 == 1)ans += digit;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp fixed << setprecision
#define pb(x) push_back(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, Z, W;
    cin >> N >> Z >> W;
    int a[N];
    rep(i, N)  cin >> a[i];
    int ans = abs(W-a[N-1]);
    if(N > 1) ans = max(ans, abs(a[N-1]-a[N-2]));
    cout << ans << endl;
}

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

using namespace std;

struct Dsu {
    int n;
    vector<int> p;
    
    Dsu(int _n) { n = _n; p.resize(n); init(); }
    inline void init() {
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
    }
    inline int find(int x) {
        return p[x] == x ? x: p[x] = find(p[x]);
    }
    inline bool join(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        p[y] = x; return true;
    }
    inline bool check(int x, int y) {
        return find(x) == find(y);
    }
};

void solve() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
        x--;
    }
    Dsu d(n);
    for (int _ = 0; _ < m; _++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        d.join(x,y);
    }
    vector<set<int>> group(n);
    for (int i = 0; i < n; i++) {
        group[d.find(i)].insert(i);
    }
    int res = 0;
    for (auto& g: group) {
        int cnt = 0;
        for (int i: g){
            if (g.find(a[i]) != g.end())
                cnt++;
        }
        res += cnt;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 10368
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll dp[n+1]={0};
	dp[0]=2;
	dp[1]=1;
	rep(i,2,n+1){
		dp[i]=dp[i-1]+dp[i-2];
	}
	cout << dp[n];
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 1e5+5;
const ll MOD = 1e9+7;

int main()
{
    int n, num, mini, ans = -inf;
    cin >> n >> mini;
    while (--n)
    {
        cin >> num;
        ans = max(ans, num-mini);
        mini = min(mini, num);
    }
    cout << ans << endl;

    return 0;
}



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

int main(){
    long long n;
    cin >> n;
    vector<long long> p(n);

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

    vector<long long> dp(n+1, 0);

    long long maxv = 0;
    for(long long i = 0; i < n ;i++){
        long long t = p[i];
        dp[t] = dp[t-1] + 1;
    }

    for(long long i = 0; i <= n ;i++){
        maxv = max(maxv, dp[i]);
    }

    cout << n - maxv << endl;
    return 0;
}

Measured memory_bytes: 6432
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(x):
  if z[x]==-1:
  	z[x]=max([f(i) for i in v[x]]+[-1])+1
  return z[x]
n,m=map(int,raw_input().split())
v=[[] for _ in xrange(n)]
for x,y in [map(int,raw_input().split()) for _ in xrange(m)]:
  v[x-1].append(y-1)
z=[-1]*n
for i in xrange(n):
  if z[i]==-1:
    f(i)
print max(z)

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

#define MAX_NUM 100000
struct Drink{
	unsigned long long money;
	unsigned long long num;
};
Drink drink[MAX_NUM + 10];  

bool operator < (Drink a, Drink b) {
	return a.money < b.money;
} 

int main() {
	unsigned long long  N, M;
	cin >> N >> M;
	
	for(int i = 0; i < N; ++i) {
		scanf("%llu%llu", &drink[i].money, &drink[i].num);
	}
	
	sort(drink, drink + N);
	
	int cou = 0;
	unsigned long long money = 0;
	for(int i = 0; i < N; ++i) {
		if(drink[i].num + cou <= M) {
			cou += drink[i].num;
			money += drink[i].num * drink[i].money;
		} else {
			money += (M - cou) * drink[i].money;
			break;
		}
	}
	
	cout << money;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) 
{
	int H;
	int W;
	int i;
	int j;
	
	H = 1;
	W = 1;
	
	while(1)
	{
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0)
		{
			break;
		}
		
		for(i = 0; i < H; i++)
		{
			for(j = 0; j < W; j++)
			{
				if(i == 0 || i == H - 1 || j == 0 || j == W - 1)
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
		
	return 0;
}

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

int main() {
  int N, p=0, w=0, y=0, g=0, sum;
  string a;
  cin >> N;
  
  for (int i=0; i<N; i++){
    cin >> a;
    if(a== "P")
      p=1;
    else if(a== "W")
      w=1;
    else if(a== "G")
      g=1;
    else
      y=1;
  }
  sum = p+w+g+y;
  if(sum==3){
    cout << "Three" << endl;
  }
  if (sum==4)
    cout << "Four" << endl;
}

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


int main(void)
{
	char s[100000] = {0};
	int n,i,j,count = 0;

	scanf("%s", s);

	n = strlen(s);


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

	printf("%d\n", count);



	return 0;
}

Measured memory_bytes: 256
#include "iostream"
using namespace std;

int main()
{
	int a, b;
	char op;
	while (cin >> a >> op >> b && op != '?')
	{
		if (op == '+')
		{
			cout << a + b << endl;
		}
		else if (op == '-')
		{
			cout << a - b << endl;
		}
		else if (op == '*')
		{
			cout << a * b << endl;
		}
		else if (op == '/')
		{
			cout << a / b << endl;
		}
	}
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

using mint = modint998244353;

template<class T>
struct Optional {
    bool valid;
    T x;
    operator bool() {return valid;}
    Optional(const T& x): valid(true), x(x) {}
    Optional(): valid(false) {}
    T& value() {return x;}
};

template <class S,
          S (*op)(S, S),
          class F,
          F (*composition)(F, F),
          S (*mapping)(F, S)>
class lazy_lazy_segtree {
    template<class T, T (*f)(T, T)>
    static Optional<T> funcmap(Optional<T> x, Optional<T> y) {
        if (!x) return y;
        if (!y) return x;
        return f(x.value(), y.value());
    }
    template<class T>
    static Optional<T> idfunc() { return {};};
    static Optional<S> Optional_mapping(Optional<F> f, Optional<S> s) {
        if (f && s) {
            return mapping(f.value(), s.value());
        } else {
            return s;
        }
    }
    template<bool (*g)(S)> static bool map_g(Optional<S> x) {return x ? g(x.value()) : true;}
public:
    lazy_segtree<Optional<S>,funcmap<S, op>,idfunc<S>,Optional<F>,Optional_mapping,funcmap<F, composition>,idfunc<F>> seg;
    lazy_lazy_segtree() : lazy_lazy_segtree(0) {}
    lazy_lazy_segtree(int n) : seg(std::vector<Optional<S>>(n)) {}
    lazy_lazy_segtree(const std::vector<S>& v) : seg(std::vector<Optional<S>>(v.begin(),v.end())) {}
    void set(int p, S x) {seg.set(p, x);}
    S get(int p) {
        auto x = seg.get(p);
        return x ? x.value() : S();
    }
    S prod(int l, int r) {
        auto x = seg.prod(l, r);
        return x ? x.value() : S();
    }
    S all_prod() {
        auto x = seg.all_prod();
        return x ? x.value() : S();
    }
    void apply(int p, F f) {seg.apply(p, f);}
    void apply(int l, int r, F f) {seg.apply(l, r, f);}
    template <bool (*g)(S)> int max_right(int l) {return seg.template max_right<map_g<g>>(l);}
    template <class G> int max_right(int l, G g) {return seg.max_right(l, [&g](Optional<S> x){return x ? g(x.value()) : true;});}
    template <bool (*g)(S)> int min_left(int r) {return seg.template min_left<map_g<g>>(r);}
    template <class G> int min_left(int r, G g) {return seg.min_left(r, [&g](Optional<S> x){return x ? g(x.value()) : true;});}
};

struct S {mint x, w;};
S op(S l, S r) {return {l.x * r.w + r.x, l.w * r.w};}
int composition(int l, int r) { return l;}
const mint inv9 = mint(1) / 9;
S mapping(int l, S r) { return {(r.w - 1) * inv9 * l, r.w};}

int main() {
    int n, q;
    cin >> n >> q;
    lazy_lazy_segtree<S, op, int, composition, mapping> seg(vector<S>(n, {1, 10}));
    while(q--) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        seg.apply(l, r, d);
        cout << seg.all_prod().x.val() << endl;
    }
}

Measured memory_bytes: 15408
#include <bits/stdc++.h>
using namespace std;
int par[100010];
int root(int x) {
    if (x == par[x]) {
        return x;
    }
    return par[x] = root(par[x]);
}
void unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx != ry) {
        par[rx] = ry;
    }
}
int main () {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        par[i] = i;
    }
    vector<vector<int>> v(M);
    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++) {
            int L;
            cin >> L;
            L--;
            v[L].push_back(i);
        }
    }
    for (int i = 0; i < M; i++) {
        int l = v[i].size();
        if (l >= 2) {
            for (int j = 1; j < l; j++) {
                unite(v[i][0], v[i][j]);
            }
        }
    }
    for (int i = 1; i < N; i++) {
        if (root(i) != root(0)) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}

Measured memory_bytes: 5112
#include <iostream>
#include<string.h>
using namespace std;
int main(void){
    // Here your code !
  char S[28];
  int a=0;
  cin>>S;
  for(int i=0;i<strlen(S);++i){
      for(int h=i+1;h<strlen(S);++h)
      if(S[h]==S[i]){
          a=1;
          break;
      }
  }
  if(a==0) cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp21
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = Convert.ToInt32(input[0]);
            int b = Convert.ToInt32(input[1]);
            int sum = 0;
            for (int i = 0; i < 2; i++)
            {
                if (a >= b)
                {
                    sum += a;
                    a--;
                }
                else
                {
                    sum += b;
                    b--;
                }

                
            }
            
            Console.WriteLine(sum);
            Console.Read();

        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N)cin>>A.at(i);
  sort(A.begin(),A.end());
  for(int i=0;i<N-1;i++){
    if(A.at(i)==A.at(i+1)){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,l,r) for(int i=(l);i<(r);i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp 
// g++ -O3 -mtune=native -march=native -mfpmath=both prac.cpp

int main(){
    ll x=1,y=0,z=0,n,m=0,k,h,ans=0,w,sum=1,Max=-1e9-1,cnt=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> n >> k >> m;
    VL a(n);
    if(m < 1e9){
        rep(i,n){
            a[i] = m;
        }
        for(int i=k; i<n;i++){
            a[i]++;
        }
    }
    else{
        rep(i,n){
            a[i] = m;
        }
        for(int i=k; i<n;i++){
            a[i]=1;
        }
    }


    
    rep(i,n){
        if(i==n-1){
            cout << a[i] << endl;
        }
        else cout << a[i] << " ";
    }
    return 0;    
}


 

Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> dp(3);
    rep(t, 0, N) {
        vector<int> p(3);
        cin >> p[0] >> p[1] >> p[2];
        vector<int> ndp(3);
        rep(i, 0, 3) {
            rep(j, 0, 3) {
                if (i == j) continue;
                ndp[j] = max(ndp[j], dp[i] + p[j]);
            }
        }
        dump(dp, ndp);
        swap(ndp, dp);
    }
    cout << *max_element(all(dp)) << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $X, $Y);
$ans = 0;
if ($X === 1) {
    $ans += 300000;
}
if ($X === 2) {
    $ans += 200000;
}
if ($X === 3) {
    $ans += 100000;
}
if ($Y <= 3) {
    $ans += (4 - $Y) * 100000;
}
if ($X + $Y === 2) {
    $ans += 400000;
}
echo $ans;


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
int main(){
    ll n;cin>>n;
    if(n%2){cout<<0<<endl;return 0;}
    ll ans=0;
    n/=2;
    while(n){
        ans+=n/5;
        n/=5;

    }
    cout<<ans<<endl;
}

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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

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

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

	return 0;
}


Measured memory_bytes: 256
N, M, C = STDIN.gets.chomp.split(' ').map(&:to_i)
B = STDIN.gets.chomp.split(' ').map(&:to_i)

A = Array.new(20)

for i in 0..N - 1 do
  A[i] = STDIN.gets.chomp.split(' ').map(&:to_i)
end

result = 0
answer = 0
for j in 0..N - 1 do
  for k in 0..M - 1 do
  	answer += A[j][k] * B[k]
  end
  answer += C
  if answer > 0 then
    result += 1
  end
  answer = 0
end
puts result

Measured memory_bytes: 1788
n,m=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]

route=[1]*n

for i in range(m):
    a,b=[int(x) for x in input().split()]
    a-=1
    b-=1

    if h[b]>=h[a]:
        route[a]=0
    if h[a]>=h[b]:
        route[b]=0



print(sum(route))

Measured memory_bytes: 20116
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>
#include <string>
#include <bits/stdc++.h>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;

static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;
using pint = pair<int,int>;


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

  ll a[n],b[n],c[n];

  REP(i,n)
  {
    cin >> a[i];
    --a[i];
  }
  REP(i,n)
  {
    cin >> b[i];
  }
  REP(i,n-1)
  {
    cin >> c[i];
  }

  ll res = 0;

  ll mae = -1;
  REP(i,n)
  {
    if(i != 0 && a[i] - a[i-1] == 1)
    {
      res += c[a[i-1]];
    }
    res += b[a[i]];
  }

  cout << res <<  endl;

  return 0;
}



Measured memory_bytes: 384
import sys
input = sys.stdin.readline


class LiChaoTree:
    """Convex Hull TrickをSegmentTree上で行う
    add_line: 直線集合に line = (傾きa, 切片b) の直線を追加する
    get_min: 座標xにおいて直線集合が取りうる最小値を求める
    """
    def __init__(self, x_coords):
        self.INF = 10 ** 20
        self.n = len(x_coords)
        self.size = 2 ** (self.n - 1).bit_length()
        self.to_ind = {x: ind for ind, x in enumerate(x_coords)}
        self.x_coords = x_coords + [self.INF] * (self.size - self.n)
        self.data = [None] * (2 * self.size)

    def add_line(self, line):
        """直線の集合に line = (傾きa, 切片b) の直線を追加する"""
        left = 0
        right = self.size
        k = 1
        while True:
            if self.data[k] is None:
                self.data[k] = line
                return

            mid = (left + right) // 2
            lx = self.x_coords[left]
            mx = self.x_coords[mid]
            rx = self.x_coords[right - 1]

            need_l_update = self.f(line, lx) < self.f(self.data[k], lx)
            need_m_update = self.f(line, mx) < self.f(self.data[k], mx)
            need_r_update = self.f(line, rx) < self.f(self.data[k], rx)

            if need_l_update and need_r_update:
                self.data[k] = line
                return

            if not need_l_update and not need_r_update:
                return

            if need_m_update:
                self.data[k], line = line, self.data[k]

            if need_l_update != need_m_update:
                right = mid
                k = 2 * k
            else:
                left = mid
                k = 2 * k + 1

    def f(self, line, x):
        """f(x)を求める"""
        a, b = line
        return a * x + b

    def get_min(self, x):
        """座標xにおいて直線集合が取りうる最小値を求める"""
        k = self.to_ind[x] + self.size
        res = self.INF
        while k > 0:
            if self.data[k] is not None:
                res = min(res, self.f(self.data[k], x))
            k = k >> 1
        return res


n, c = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**20
 
lct = LiChaoTree(h)
dp = [INF] * n
dp[0] = 0
lct.add_line((-2 * h[0], h[0] ** 2 + dp[0]))
 
for i in range(1, n):
    dp[i] = lct.get_min(h[i]) + c + h[i] ** 2
    lct.add_line((-2 * h[i], h[i] ** 2 + dp[i]))
print(dp[-1])

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

int main()
{
    int i,j,bj;
    char a[4],b[4];
    while(~scanf("%s %s",a,b)){
     bj=0;
    for(i=0;i<3;i++){
        if(a[i]==b[2-i])
        {
            bj++;
        }
        else
        {
            bj=0;
        }
    }
    if(bj==3)
    {
        printf("YES\n");
    }
    else
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(ll i=l;i<r;i++)
#define LINF (ll)1e18
#define INF (int)1e9
struct aaa{aaa(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(10);};}aaaaaaa;
inline void in() {}
template <class Head, class... Tail>
inline void in(Head&& head,Tail&&... tail){
    cin>>head;
    in(move(tail)...);
}
template <class T>
inline void out(T t) {
    cout<<t<<'\n';
}
template <class Head, class... Tail>
inline void out(Head head,Tail... tail){
    cout<<head<<' ';
    out(move(tail)...);
}

int main(){
    int n;
    in(n);
    int a[n];
    rep(i,0,n)in(a[i]);
    out(*max_element(a,a+n)-*min_element(a,a+n));
}



















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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n; i >= a; i--)
#define pb              push_back
#define lb              lower_bound		// first element >= val(itr) 
#define ub              upper_bound		// first element >  val(itr)
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))	//x can be 0 or -1

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

#ifdef LOCAL_TEST
	#include"/home/shrey/debug.h"
#endif

const ll inf = 1e18;
const int nax = 1e5 + 5;
ll dp[10][20][10][2];
ll k,n;
vector<ll>digits;

void pre(ll x)
{
	//dbg(x);
	digits.clear();
	while(x)
	{
		digits.pb(x%10);
		x /= 10;
	}
	
	reverse(all(digits));
	n = digits.size();
	
	forn(i,0,10)
	{
		forn(j,0,20)
		{
			forn(k,0,10)
			{
				forn(p,0,2)
				{
					dp[i][j][k][p] = -1;
				}
			}
		}
	}
}

ll count(ll idx,ll len,ll prev,bool allow)
{
	if(prev < 0 || prev>=10)
	{
		return 0;
	}
	
	if(idx == len)
	{
		return 1;
	}
	
	if(dp[idx][len][prev][allow] != -1)
	{
		return dp[idx][len][prev][allow];
	}
	
	ll ans = 0;
	if(allow)
	{
		ans += count(idx+1,len,prev-1,1);
		ans += count(idx+1,len,prev,1);
		ans += count(idx+1,len,prev+1,1);
	}
	else
	{
		forn(i,prev-1,prev+2)
		{
			if(i > digits[idx])
			{
				continue;
			}
			if(i == digits[idx])
			{
				ans += count(idx+1,len,i,0);
			}
			else
			{
				ans += count(idx+1,len,i,1);
			}
		}
	}
	
	return dp[idx][len][prev][allow] = ans;
}

bool ok(ll x)
{
	pre(x);
	
	ll cnt = 0;
	forn(i,1,19)	//length of numbers
	{
		forn(j,1,10)	//first number
		{
			if(i<n)
			{
				cnt += count(1,i,j,1);
			}
			else if(i == n)
			{
				if(j == digits[0])
				{
					cnt += count(1,i,j,0);
				}
				else if(j<digits[0])
				{
					cnt += count(1,i,j,1);
				}
			}
		}
	}
	//cout<<cnt<<endl;
	return cnt>=(k);
}

void SolveTestCase()
{
	cin>>k;
	
	ll lo = -1, hi = 1e18;
	ll ans = 0;
	//bool t = ok(3234566667);
	while(hi-lo>1)
	{
		ll mid = (lo+hi)/2;
		//cout<<mid<<endl;
		if(ok(mid))
		{
			ans = mid;
			hi = mid;
		}
		else
		{
			//ans = mid;
			lo = mid;
		}
	}
	cout<<ans;
}

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	forn(i,0,t)
	{
		SolveTestCase();
	}

	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

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

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	string s;
	cin >> s;
	if (s[3] == s[2] && s[4] == s[5])
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <string>

using namespace std;

using ll = long long;

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

	if (str[2] == str[3] && str[4] == str[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, f[MAXN];
int dp[MAXN];
II a[MAXN];
set<II> s;
int MOD = 998244353;

void preProcess() {
    sort(a+1, a+n+1);
    FORE(i,n,1) {
        II r = a[i];
        while (1) {
            set<II>::iterator it = s.lower_bound(r);
            if (it == s.end()) break;
            if (r.SE < it->FI) break;
            r.SE = max(r.SE, it->SE);
            s.erase(it);
        }
        f[i] = r.SE;
        s.insert(r);
    }
}

int activate(int u) {
    int r = f[u];
    int dau = 1, cuoi = n;
    while (dau <= cuoi) {
        int mid = (dau + cuoi) >> 1;
        if (a[mid].FI > r) cuoi = mid-1;
        else dau = mid+1;
    }
    return cuoi;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) {
        int u, v;
        cin >> u >> v;
        a[i] = II(u, u+v-1);
    }
    preProcess();
    dp[0] = 1;
    FOR(i,0,n-1) {
        dp[i+1] = (dp[i+1] + dp[i]) % MOD;
        int x = activate(i+1);
        dp[x] = (dp[x] + dp[i]) % MOD;
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define R register
#define LL long long
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
int n,ans=0x3f3f3f3f;
inline int get_num(R int x){
	R int ret=0;
	while(x)ret+=x%10,x/=10;
	return ret;
}
int main(){
	read(n);
	for(R int a=1,b,c,d;a<n;++a){
		b=n-a;
		c=get_num(a);
		d=get_num(b);
		ans=Min(ans,c+d);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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 run() {
    input! {
        n: usize,
        m: usize,
        a: [usize1; n],
    }
    let mut imos1 = vec![0; 2 * m + 1];
    let mut imos2 = vec![0; 2 * m + 1];
    let mut sum = 0;
    for a in a.windows(2) {
        let x = a[0];
        let y = a[1];
        if x < y {
            let d = y - x;
            sum += d;
            let r = y;
            let l = x;
            imos2[r] -= d;
            imos2[l] += d;
            imos1[r] += 1;
            imos1[l] -= 1;
            imos2[l] -= d;
        } else {
            let d = y + m - x;
            sum += d;
            let r = y + m;
            let l = x;
            imos2[r] -= d;
            imos2[l] += d;
            imos1[r] += 1;
            imos1[l] -= 1;
            imos2[l] -= d;
        }
    }
    for i in (0..(2 * m)).rev() {
        imos1[i] += imos1[i + 1];
    }
    for i in (0..(2 * m)).rev() {
        imos2[i] += imos1[i] + imos2[i + 1];
    }
    let mut ans = sum;
    for i in 0..m {
        let cost = sum + imos2[i] + imos2[i + m];
        ans = std::cmp::min(ans, cost);
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 10492
#include<bits/stdc++.h>
using namespace std;
int main(){
    int m,i,c0=0,c1=0,c2=0,c3=0;
    int n;
    cin>>n;
    string s;
    while(n--){
        cin>>s;
        if(s[0]=='A')c0++;
        if(s[0]=='W')c1++;
        if(s[0]=='T')c2++;
        if(s[0]=='R')c3++;
    }
    cout<<"AC x "<<c0<<"\n";
    cout<<"WA x "<<c1<<"\n";
    cout<<"TLE x "<<c2<<"\n";
    cout<<"RE x "<<c3<<"\n";
    return 0;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
Created on Sun May  3 21:27:48 2020
"""

import sys
import numpy as np
import itertools

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

N = int(input())
#X, Y = map(int,input().split())
A = list(map(int,input().split()))

A = np.array(A)
B = np.arange(N)

x = A - B
y = A + B

x.sort()
y.sort()

ans = 0
i, j = 0, N - 1
#pre = 10**10
x1, y1 = 0, 0
while i < N and j >= 0:
    if -x[i] < y[j]:
        j -= 1
    elif -x[i] > y[j]:
        i += 1
    else:
        x1,y1 = 1, 1
        pre = y[j]
        while pre == -x[i+1]:
            x1 += 1
            i += 1
#            print('x',pre,x1)
        while pre == y[j-1]:
            y1 += 1
            j -= 1
#            print('y',pre,y1)
        i += 1
        j -= 1
        ans += x1 * y1
#        print()
#    print(i,j,x[i],y[j],x1,y1,ans)
print(ans)

Measured memory_bytes: 50924
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    A = list(map(int, input().split()))
    print(A.index(0) + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65216
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

#define P 998244353

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}
int compl(const void *a, const void *b){return (*(long*)a>*(long*)b)-(*(long*)a<*(long*)b);}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }

inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

int p;
int n;
char s[200001];

void solve25(void){
	long ans=0;
	for(int i=0; i<n; i++){
		if(s[i]%p==0){
			ans+=i+1;
		}
	}
	printf("%ld\n", ans);
}

long b[200001];

int bs(long x){
	int l=0, r=n;
	while(l<=r){
		int m=(l+r)/2;
		if(b[m]>=x) r=m-1; else l=m+1;
	}
	return l;
}

void solve(void){
	int i;
	b[0]=0;
	b[1]=1;
	for(i=2; i<=n; i++){
		b[i]=b[i-1]*10%p;
	}
	for(i=1; i<=n; i++){
		b[i]*=s[n-i];
		b[i]+=b[i-1];
		b[i]%=p;
	}
	qsort(b, n+1, sizeof(long), compl);
	for(i=0; i<n&&b[i]==0; i++);
	long ans2 = (long)i*(i-1)/2;
	long ans=0;
	for(; i<=n; i++){
		ans += bs(b[i]+1)-bs(b[i])-1;
	}
	ans/=2;
	ans+=ans2;
	printf("%ld\n", ans);
}

int main(void){
	n=nextint();
	p=nextint();
	nextstr(s);
	for(int i=0; i<n; i++) s[i]-='0';
	if(n==0 && s[0]==0){
		puts("1");
		return 0;
	}

	if(p==2 || p==5){
		solve25();
	}else{
		solve();
	}
}


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

typedef long long ll;

const ll MOD = 1000000007;

int main()
{
	int n;
	scanf("%d", &n);
	vector<ll> a(n, 0);
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &a[i]);
	}
	ll ans = 0, sum = a[0];
	for (int i = 1; i < n; ++i) {
		ans = (ans+sum*a[i]%MOD)%MOD;
		sum = (sum+a[i])%MOD;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 4856
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#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, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    string s;
    cin >> s;
    string ans = "CODEFESTIVAL2016";
    int cnt = 0;
    REP(i, ans.size()){
        if(s[i] != ans[i]) cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<math.h>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
int maxa(int x,int y)
{
	if(x>y)
		return x;
	return y;
}
int mina(int v,int u)
{
	if(v<u)
		return v;
	return u;
}
int main()
{
	int t,n,i,maxv=-2000000000,R[200010];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&R[i]);
	int minv=R[1];
	for(i=2;i<=n;i++)
	{
		maxv=maxa(maxv,R[i]-minv);
		minv=mina(minv,R[i]);
	}
	printf("%d\n",maxv);
	return 0;
}


Measured memory_bytes: 2524