akhauriyash/Code-Regression huggingface dataset:
char s[101];
A(){
	char*p=s,l=0;
	if(*p=='>'&&*++p=='\''){
		for(;*++p=='=';)l++;
		if(l>0&&*p=='#'){
			for(;*++p=='=';)l--;
			if(l==0&&*p=='~'&&*++p==0)
				return 1;
		}
	}
	return 0;
}
B(){
	char*p=s,l=0;
	if(*p=='>'&&*++p=='^'){
		for(;*++p=='Q';l++)
			if(*++p!='=')
				return 0;
		if(l>0&&*p=='~'&&*++p=='~'&&*++p==0)
			return 1;
	}
	return 0;
}
main(){
	scanf("%*d\n");
	for(;~scanf("%[^\n]\n",s);){
		if(A())
			puts("A");
		else if(B())
			puts("B");
		else
			puts("NA");
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a.back() - a[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;


    while(a >= b){
        b <<= 1;
        --k;
    }
    while(b >= c){
        c <<= 1;
        --k;
    }
    cerr << a << ' ' << b << ' ' << c << '\n';
    cerr << k << '\n';
    Judge(k >= 0);


    
    
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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*(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;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
vector<ll> z_algo(vector<ll> S) {//0-index
	ll N = S.size();

	vector<ll> A(N, 0);


	ll c = 0;
	repn(i, N - 1) {
		if (c > 0 && i - c + A[i - c] < A[c]) { A[i] = A[i - c]; }
		else {
			ll j = max(0, c + A[c] - i);
			while (i + j < N && S[j] == S[i + j]) { j++; }
			A[i] = j;
			c = i;
		}
	}

	A[0] = N;

	return A;
}

int main() {
	ll N;
	string S;
	cin >> N >> S;

	ll mx = 0;

	rep(i, N) {
		string T = S.substr(i, N - i);
		//cout << T << endl;
		vector<ll> t;
		rep(i, T.size()) { t.push_back(T[i]); }
		vll v = z_algo(t);
		repn(i, v.size()-1) {
			ll t = min(i, v[i]);
			mx = max(t, mx);
		}
	}

	cout << mx << endl;
}


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

int v,e;
ll dp[101][101];
const ll inf=9999999999;

int main(){
 ios::sync_with_stdio(false);
 cin.tie(0);
 cin>>v>>e;
 for(int i=0;i<v;i++)for(int j=0;j<v;j++)if(i!=j)dp[i][j]=inf;
 for(int i=0;i<e;i++){
  int s,t;cin>>s>>t;
  dp[s][t]=-1;
 }
 for(int k=0;k<v;k++){
  for(int i=0;i<v;i++){
   if(dp[i][k]==inf)continue;
   for(int j=0;j<v;j++){
    if(dp[k][j]==inf)continue;
    dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
   }
  }
 }
 for(int i=0;i<v;i++)if(dp[i][i]<0){cout<<1<<"\n";return 0;}
 cout<<0<<"\n";
}

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

int min(int A,int B){
    return A<B?A:B;
}

int MAX(int A,int B){
    return A>B?A:B;
}

int main(void){
    int n;
    scanf("%d",&n);
    int v[n],ans=0;
    for (int i=0; i<n; i++){
        scanf("%d",&v[i]);
    }
    for (int i=0; i<n; i++){
        int c;
        scanf("%d",&c);
        if (v[i]>c){
            ans+=v[i]-c;
        }
    }
    printf("%d\n",ans);
    return 0 ;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int min(int a, int b)
{
  if(a <= b)
  return a;
  else
  return b;
}

int main(void)
{
  int H, W, h, w;
  scanf("%d %d", &H, &W);
  scanf("%d %d", &h, &w);
  printf("%d\n", H*W-h*W-w*(H-h));
  return 0;
}

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

//🔴
//Union_Find木
//連結とグループ一致判定
//蟻本実装
//O(α)　アッカーマン関数


//n要素の初期化
void init(int n, vector<int>& par, vector<int>& rank){
    for(int i = 0; i < n; i++){
        par[i] = i;
        rank[i] = 0;
    }
}

// 木の根を求める
int find(int x, vector<int>& par, vector<int>& rank){
    if(x == par[x]) return x;
    else return par[x] = find(par[x], par, rank);
}

//木を連結
void unite(int x, int y, vector<int>& par, vector<int>& rank){

    x = find(x, par, rank);
    y = find(y, par, rank);

    if(x == y) return;

    if(rank[x] < rank[y]) par[x] = y;
    else{
        par[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    } 
}


//一致判定
bool same(int x, int y, vector<int>& par, vector<int>& rank){
    return find(x, par, rank) == find(y, par, rank);
}

int main(){

    int n, m; cin >> n >> m;                        //要素数 クエリ数
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    vector<int> par(n);                             //parents   親
    vector<int> rank(n);                            //rank      木の深さ
    init(n, par, rank);

    for(int i = 0; i < m; i++){
        int x, y; cin >> x >> y;             //t == 0, 連結　t == 1, 判定
        x--; y--;
        unite(x, y, par, rank);
        
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        int v = p[i];
        ans += same(i, v, par, rank);
    }

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

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;


int main(){
    string s;
    int ans=0,count =0;
    cin >>s;
    for(int i=0;i<s.size();i++){
        for(int j=i;j<s.size();j++){
            if(s[j] =='A' ||s[j] =='T'||s[j] =='C'||s[j] =='G'){
                count ++;
            }
            else break;
        }
        ans =max(ans,count);
        count =0;
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

long long MOD=1000000007;

int main(void){
    string L;
    cin>>L;
    long long ans=0;
    vector<long long> temp3(L.length());
    vector<long long> temp2(L.length());
    vector<bool> is1(L.length(),false);
    temp3[L.length()-1]=1;
    temp2[0]=1;
    is1[0]=true;
    for(int i=1;i<L.length();i++){
        if(L[i]=='1'){
            temp2[i]=(temp2[i-1]*2)%MOD;
            is1[i]=true;
        }else{
            temp2[i]=temp2[i-1];
        }
    }
    for(int i=L.length()-2;i>=0;i--){
        temp3[i]=(temp3[i+1]*3)%MOD;
    }
    for(int i=0;i<L.length();i++){
        if(is1[i]){
            ans=(ans+(temp3[i]*temp2[i])%MOD)%MOD;
        }
    }
    ans=(ans+temp2[L.length()-1]*2)%MOD;
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;

int main() {
    string a;
    cin >> a;
    ll x=0;
    for (int i=0;i<4;++i){
        if (a[i]=='+'){
            ++x;
        }else{
            --x;
        }
    }
    cout << x << endl;
    return 0;
}


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

int main(void){
  int n, l, i;
  cin >> n >> l;
  string strings[n];
  for(i = 0; i < n; i++){
    cin >> strings[i];
  }
  sort(strings, strings+n);
  for(i = 0; i < n; i++){
    cout << strings[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000
 
using namespace std;
 
int n,m;
ll L;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m >> L;

	ll w,x,y;
	ll mat[n][n];

	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			mat[i][j] = INF;
		}
	}

	for (int i = 0; i < m; ++i){
		cin >> x >> y >> w;
		x--;
		y--;
		mat[x][y] = w;
		mat[y][x] = w;
	}


	for (int k = 0; k < n; ++k){
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < n; ++j){
				if(mat[i][k]+mat[k][j] < mat[i][j]){
					mat[i][j] = mat[i][k]+mat[k][j];
				}
			}
		}
	}

	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			if(mat[i][j] > L){
				mat[i][j] = INF;
			}else{
				mat[i][j] = 1;
			}
		}
	}

	for (int k = 0; k < n; ++k){
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < n; ++j){
				if(mat[i][k]+mat[k][j] < mat[i][j]){
					mat[i][j] = mat[i][k]+mat[k][j]; 
				}
			}
		}
	}	

	int q;
	cin >> q;
	int s,t;
	while(q--){
		cin >> s >> t;
		s--;t--;
		if(mat[s][t] < INF){
			cout << mat[s][t]-1 << '\n';
		}else{
			cout << -1 << '\n';
		}
	}
	

	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
int main(){
  int n,x;
  scanf("%d%d", &n, &x);
  int i, l, sum=0, c=1;
  for(i=0;i<n;i++){
    scanf("%d", &l);
    sum+=l;
    if(sum<=x) c++;
  }
  printf("%d", c);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int K, X; cin >> K >> X;
  for (int i = X-K+1; i <= X+K-1; i++) {
    cout << i << ' ';
  }
  cout << endl;
  return 0;
}


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

namespace AtCoder.ABC141
{
    class QuestionD
    {
        public static void Main(string[] args)
        {
            // 文字列配列の入力
            var inputIntArray1 = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int n = inputIntArray1[0];
            int m = inputIntArray1[1];

            // 整数配列の入力
            var aArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            List<long>[] groups = new List<long>[32];
            for(int i = 0; i < 32; i++)
            {
                groups[i] = new List<long>();
            }

            //すべての数字をバイト列に変換し、長さごとにグループ化する
            for(int i = 0; i < n; i++)
            {
                var b = Convert.ToString(aArray[i], 2);
                groups[b.Length].Add(aArray[i]);
            }

            for(int i = 31; i >= 0; i--)
            {
                if (m == 0)
                {
                    //割引券がなくなったら終わり
                    break;
                }

                var list = groups[i];
                if(list.Count() == 0)
                {
                    continue;
                }
                if(list.Count <= m)
                {
                    //一番大きいグループ全部に割引券を使える
                    m -= list.Count;
                    if (i != 0)
                    {
                        foreach (var b in list)
                        {
                            groups[i - 1].Add(b >> 1);
                        }
                    }
                    groups[i] = null;
                }
                else
                {
                    //このグループの中身をソートして、高いものだけシフト演算
                    var tmp = list.OrderBy(l => l).ToList();
                    for(int j = 0; j < m; j++)
                    {
                        //クーポンの枚数だけ、末尾を移していく
                        var index = tmp.Count() - 1;
                        var item = tmp[index];
                        if(i != 0)
                        {
                            groups[i - 1].Add(item >> 1);
                        }
                        tmp.RemoveAt(index);
                    }
                    groups[i] = tmp;
                    m = 0;
                }
            }


            long result = 0;
            //全部足す
            foreach(var group in groups)
            {
                if(group == null)
                {
                    break;
                }
                foreach(var item in group)
                {
                    result += item;
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 34268
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int w, a, b; cin >> w >> a >> b;

    cout << max(abs(a-b) - w,0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>
#include <bitset>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    bitset<2020> A[2020];
    for (int n = 1; n < N; ++n) {
        string S;
        cin >> S;
        for (int m = 0; m < n; ++m) {
            A[n][m] = S[m]-'0';
            A[m][n] = 1-A[n][m];
        }
    }
    
    bitset<2020> DP[2020];
    for (int n = 0; n < N; ++n) {
        DP[n][n] = 1;
    }
    for (int d = 1; d <= N-1; ++d) {
        for (int i = 0; i+d < N; ++i) {
            int j = i+d;
            DP[j][i] = (A[i] & DP[i+1] & DP[j]).any();
            DP[i][j] = (A[j] & DP[i] & DP[j-1]).any();
        }
    }
    int Res = 0;
    for (int n = 0; n < N; ++n) {
        if (DP[0][n] & DP[N-1][n]) ++Res;
    }
    cout << Res << endl;

    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>

using namespace std;


int main()
{
	int x,a,b;
	cin>>x>>a>>b;
	if(a-b>=0){
		cout<<"delicious"<<endl;
	}
	else if(b-a<=x){
		cout<<"safe"<<endl;
	}
	else if(b-a>x){
		cout<<"dangerous"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())

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

	string ans = "Yes";
	SORT(s); SORT(t); rev(t);
	rep(i, 0, s.size()) {
		if (i == (s.size() - 1)) {
			if (s.size() >= t.size()) {
				ans = "No";
			}
		}
		if (s[i] < t[i]) break;
		else if (s[i] > t[i]) {
			ans = "No";
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
datalist=list(map(int,input().split()))
N, A, B = datalist[0], datalist[1], datalist[2]
strings=str(input())
na,nb=0,0
out=[]
for i in range(len(strings)):
  if strings[i]=="a":
    if na + nb < A+B:
      out.append("Yes")
      na += 1
    else:
      out.append("No")
  elif strings[i]=="b":
    if na + nb < A+B:
      if nb < B:
        out.append("Yes")
        nb += 1
      else:
        out.append("No")
    else:
      out.append("No")
  else:
    out.append("No")
print("\n".join(out))


Measured memory_bytes: 10684
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <cinttypes>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

typedef pair<ll, ll> P;
inline P operator+(const P& p1, const P& p2) {
  return P(p1.first + p2.first, p1.second + p2.second);
}

int n, T;
ll sum[100001];
vector<ll> a, b, t;

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

  cin >> n >> T;
  a.resize(n);
  b.resize(n);
  t.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i) b[i] = max(a[i], b[i - 1]);
    else b[i] = a[i];
    if(i) t[i] = t[i - 1] - a[i];
    else t[i] = T - a[0];
  }

  for (int i = 0; i < n; ++i) {
    if(t[i] < 0) cout << 1 << endl;
    else cout << 2 + t[i] / b[i] << endl;
  }

  return 0;
}

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

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

  int count = 0;

  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == '1'){
      count++;
    }
  }

  cout << count << endl;
}

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

using namespace std;

int64_t solve(const string &S, vector<char> V){
    int64_t res = 0;
    for (int i = 0; i < S.size(); i++){
        if (S[i] == V[i % 2])
            res++;
    }

    return res;
}

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

    cout << min(solve(S, {'0', '1'}), solve(S, {'1', '0'}));
}

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

int main()
{
    int K;
    int A, B;
    int judge=0;
    cin >> K >> A >> B;
    for (int i=A; i<=B; i++){
        if(i%K==0){
            judge=1;
        }
    }
    if(judge==1){
        cout << "OK" << endl;
    }
    else {
        cout << "NG" << endl;
    }
}

Measured memory_bytes: 3624
#include <cstdint>
#include <iostream>
#include <limits>
#include <queue>
#include <vector>
namespace libtest {
using i32   = int32_t;
using i64   = int64_t;
using u32   = uint32_t;
using u64   = uint64_t;
using usize = std::size_t;
using uint  = unsigned int;
using ll    = long long;
using ull   = unsigned long long;
using ld    = long double;
template<typename T>
constexpr T INF = std::numeric_limits<T>::max() / 4;
struct graph
{
    graph(const usize v) : edge(v), v{v} {}
    void add_edge(const usize i, const usize j, const bool bi = false)
    {
        e++, edge[i].push_back(j);
        if (bi) { e++, edge[j].push_back(i); }
    }
    std::vector<std::vector<usize>> edge;
    const usize v;
    usize e = 0;
};
template<typename T>
struct cost_graph
{
    struct p
    {
        usize from, to;
        T cost;
    };
    cost_graph(const usize v) : edge(v), v{v} {}
    void add_edge(const usize i, const usize j, const T c, const bool bi = false)
    {
        e++, edge[i].push_back(p{i, j, c});
        if (bi) { e++, edge[j].push_back(p{j, i, c}); }
    }
    std::vector<std::vector<p>> edge;
    const usize v;
    usize e = 0;
};
template<typename T>
std::vector<T> bellman_ford(const cost_graph<T>& g, const usize r)
{
    const usize v = g.v;
    std::vector<T> d(v, INF<T>);
    d[r] = 0;
    for (usize i = 0; i < 2 * v; i++) {
        for (usize u = 0; u < v; u++) {
            for (const auto& e : g.edge[u]) {
                if (d[e.from] != INF<T> and d[e.to] > d[e.from] + e.cost) {
                    if (d[e.from] == -INF<T>) {
                        d[e.to] = -INF<T>;
                    } else {
                        d[e.to] = d[e.from] + e.cost;
                        if (i >= v) { d[e.to] = -INF<T>; }
                    }
                }
            }
        }
    }
    return d;
}
}  // namespace libtest
int main()
{
    using namespace libtest;
    usize v, e;
    std::cin >> v >> e;
    ll p;
    std::cin >> p;
    cost_graph<ll> g(v);
    for (usize i = 0; i < e; i++) {
        usize s, t;
        ll d;
        std::cin >> s >> t >> d;
        g.add_edge(s - 1, t - 1, p - d);
    }
    const auto d = bellman_ford(g, 0);
    std::cout << (d[v - 1] == -INF<ll> ? -1LL : std::max(-d[v - 1], 0LL)) << std::endl;
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void)
{
  while(1){
    int n;
    cin >> n;
    if(!n) break;
    int ret = 0;
    while(n){
      n /= 5;
      ret += n;
    }
    cout << ret << endl;
  }
}

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

int main()
{
  int N, L;
  string s[128];
  string ans = "";
  cin >> N >> L;
  for (int i = 0; i < N; i++) cin >> s[i];

  sort(s, s+N);

  for (int i = 0; i < N; i++) ans += s[i];
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;++i)
#define END(x) (*(x.end()-1))

using namespace std;
typedef long long ll;
typedef vector<vector<int>> Graph;

template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a*b/gcd(a,b);
}


template<typename T>
bool same(T x_b,T x_e,T y_b,T y_e){
    for(auto i = x_b, j = y_b; i != x_e && j != y_e;++i,++j){
        if(*i!=*j){
            return false;
        }
    }
    return true;
}

using Graph=vector<vector<int>>;//グラフ型
void dfs(const Graph &G,int v/*根*/,vector<bool> &seen){
    seen[v]=true;  //vを訪問済にする
    for(auto next_v:G[v]){ //訪問済にしたvとつながっている場所を順番に探す
        if(seen[next_v]) continue; //もし探索済みならスルー
        dfs(G,next_v,seen); //再帰的に探索
    }
}
 
void bfs(const Graph &G,queue<int> &que/*発見したが訪問はしていない*/,vector<int> &dist/*開始地点からの距離*/){
    while(!que.empty()){
        int v=que.front();//queのうち先頭のものからスタート
        que.pop();//先頭を削除
 
        for(int nv :G[v]){//vとつながっている点を列挙
            if(dist[nv]!=-1) continue;//発見済(=距離が格納されている)であればスルー
            dist[nv]=dist[v]+1;//vとつながっている点に距離の情報を追加
            que.push(nv);//vとつながっている点を発見済にする
        }
    }
}

ll q(ll a,ll b){
    if(a%15>=b){
        return a/15;
    }
    else{
        return max(a/15-1,(ll)0);
    }
}

ll w(ll a,ll n){
    return n*(q(a,n)+1)+(0+q(a,n)*15)*(q(a,n)+1)/2;
}

int main(void){
    ll n;
    cin>>n;
    ll list[]={0,1,3,3,7,7,7,14,22,22,22,33,33,46,60,60};
    ll num[]={0,1,2,2,3,3,3,4,5,5,5,6,6,7,8};
    ll ans=0;

    if(n<=15){
        cout<<list[n];
        return 0;
    }
    ans+=w(n,1);
    ans+=w(n,2);
    ans+=w(n,4);
    ans+=w(n,7);
    ans+=w(n,8);
    ans+=w(n,11);
    ans+=w(n,13);
    ans+=w(n,14);
    cout<<ans;
}
/*

*/


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

int g(int a,int b){
  int n;
  if(b==0)return a;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  if(n==2){
    cout<<max(a[0],a[1]);
    return 0;
  }
  int b[n],c[n];
  b[0]=0;
  for(i=1;i<n;i++)b[i]=g(b[i-1],a[i-1]);
  c[n-1]=0;
  for(i=n-2;i>=0;i--)c[i]=g(c[i+1],a[i+1]);
  int ma=0;
  for(i=0;i<n;i++)ma=max(ma,g(b[i],c[i]));
  cout<<ma;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
int a[101],n;
cin>>n;
int i;
for(i = 0;i < n;i++)
	cin >> a[i];
	cout << a[n-1];
	for(i=1;i<n;i++)
		cout<<" "<< a[n-i-1];
	cout << endl;
return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#include<atcoder/all>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,Q;cin>>N>>Q;
	atcoder::dsu a(N);
	while(Q--){
		int t,u,v;cin>>t>>u>>v;
		if(!t)a.merge(u,v);
		else cout<<a.same(u,v)<<"\n";
	}
}

Measured memory_bytes: 3860
r="-1 -1"
s=input()
for i in range(len(s)-2):
  if len(set(s[i:i+3]))<=2:
    r=str(i+1)+" "+str(i+3)
    break
if len(s)==2 and len(set(list(s)))==1:
  r="1 2"
print(r)

Measured memory_bytes: 9212
#include<stdio.h>
#define N 25
 
typedef struct{
  int parent;
  int left;
  int right;
}node;
 
node C[N];
 
void PreOrder(int);
void InOrder(int);
void PostOrder(int);
 
int main(){
  int n,id,i;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    C[i].parent = -1;
  } 
  
  for(i=0;i<n;i++){
    
    scanf("%d",&id);
    scanf("%d %d", &C[id].left, &C[id].right);
    
    if(C[id].left != -1) C[C[id].left].parent = id;
    
    if(C[id].right != -1) C[C[id].right].parent = id;
    
  }
 
  for(i=0; i<n; i++){
 
    if(C[i].parent == -1){
 
 
      printf("Preorder\n");
      PreOrder(i);
 
      printf("\nInorder\n");
      InOrder(i);
 
      printf("\nPostorder\n");
      PostOrder(i);
 
      printf("\n");
      break;
 
    }
  }
 
  return 0;
}
 
 
void PreOrder(int n){
  printf(" %d",n);
 
  if(C[n].left != -1) PreOrder(C[n].left);
  if(C[n].right != -1) PreOrder(C[n].right);
 
}
 
void InOrder(int n){
  if(C[n].left != -1) InOrder(C[n].left);
 
  printf(" %d",n);
 
  if(C[n].right != -1) InOrder(C[n].right);
 
}
 
void PostOrder(int n){
 
  if(C[n].left != -1) PostOrder(C[n].left);
 
  if(C[n].right != -1) PostOrder(C[n].right);
 
  printf(" %d",n);
}

Measured memory_bytes: 616
#include<algorithm>
#include<cstdio>
#include<cmath>
int main() {
    int s,a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    s=(a+b+c)/2;
    printf("%d",(int)(sqrt(s*(s-a)*(s-b)*(s-c))));
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }

const int mod = 998244353;

int main(){ 
    int n, K; cin >> n >> K;
    vector<int>L(K), R(K); 
    rep(i, K){
        cin >> L[i] >> R[i];
    }
    vector<ll> dp(n), S(n+1);
    dp[0] = 1; S[1] = dp[0];
    rept(i, 1, n){
        rep(k, K){
            int l = max(0, i - R[k]);
            int r = max(0, i - L[k] + 1);
            ll s = (S[r] + mod - S[l]) % mod;
            dp[i] = (dp[i] + s) % mod;
        }
        S[i+1] = (S[i] + dp[i]) % mod;
    }
    cout << dp[n-1] << ln;
}



Measured memory_bytes: 6428
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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 n;
    cin >> n;
    vector<ll> a(n,0);
    ll sum = 0;
    vector<ll> res(n,0);
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    res[0] = sum;
    for(ll i = 1;i < n;i += 2)res[0] -= (2*a[i]);
    repp(i,1,n)res[i] = 2*a[i-1] - res[i-1];
    rep(i,n){
        cout << res[i];
        if(i != n-1)cout << " ";
    }
    cout << "\n";
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=a;i<=b;i++){
        stringstream ss;
        ss<<i;
        string s=ss.str();
        string t=s;
        reverse(all(t));
        ans+=s==t;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N, A, B = map( int, input().split() )
MOD = 10 ** 9 + 7

def combi( n, r ):
  r = min( n - r, r )
  a = 1
  b = 1
  for i in range( 1, r + 1 ):
    a = ( a * ( n - i + 1 )) % MOD
    b = ( b * i ) % MOD

  return ( a * pow( b, MOD - 2, MOD )  % MOD ) 

n1 = combi( N, A )
n2 = combi( N, B )
ans = ( pow( 2, N, MOD ) - n1 - n2 - 1 ) % MOD
print( ans )


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] num = new int[6];

        for(int i = 0; i < num.length; i++) {
        	num[i] = sc.nextInt();
        }
        Dice dice = new Dice(num);

        int count = sc.nextInt();
        for(int i = 0; i < count; i++) {
        	int top = sc.nextInt();
            int front = sc.nextInt();
            dice.setTop(top);
            dice.setFront(front);
            System.out.println(dice.getRight());
        }
    }
}

class Dice {
	private int top;
    private int front;
    private int right;
    private int left;
    private int back;
    private int bottom;

    Dice(int[] num) {
    	top = num[0];
    	front = num[1];
    	right = num[2];
    	left = num[3];
    	back = num[4];
    	bottom = num[5];
    }

    void change(char dir) {
    	switch(dir) {
    	case 'N' : moveN(); break;
    	case 'S' : moveS(); break;
    	case 'E' : moveE(); break;
    	case 'W' : moveW(); break;
    	}
    }

    void setTop(int top) {
    	if(top != this.top) {
    		if(top == this.front) {
    			moveN();
    		} else if(top == this.right) {
    			moveW();
    		} else if(top == this.left) {
    			moveE();
    		} else if(top == this.back) {
    			moveS();
    		} else if(top == this.bottom) {
    			moveS();
    			moveS();
    		}
    	}
    }

    void setFront(int front) {
    	while(true) {
    		if(front == this.front) {
    			break;
    		}
    		moveClockwise();
    	}
    }

    void moveN() {
    	int temp = top;
    	top = front;
    	front = bottom;
    	bottom = back;
    	back = temp;
    }
    void moveS() {
    	int temp = top;
    	top = back;
    	back = bottom;
    	bottom = front;
    	front = temp;
    }
    void moveE(){
        int temp = top;
        top = left;
        left = bottom;
        bottom = right;
        right = temp;
    }
    void moveW(){
        int temp = top;
        top = right;
        right = bottom;
        bottom = left;
        left = temp;
    }
    void moveClockwise() {
    	int temp = front;
    	front = right;
    	right = back;
    	back = left;
    	left = temp;
    }

    int getTop() {
    	return top;
    }
    int getRight() {
    	return right;
    }
}


Measured memory_bytes: 26132
#include <iostream>
#include <limits.h>

using namespace std;

void solve()
{
	unsigned long long int ans = 1;
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		ans *= i;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 1152
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long[] arr = new long[n+1];
		
		arr[0] = 2;
		arr[1] = 1;
		for (int i = 2; i < arr.length; i++) 
			arr[i] = arr[i-1]+arr[i-2];
		
		System.out.println(arr[n]);
    }
}

Measured memory_bytes: 21844
class UnionFind:
  def __init__(self, size):
    self.table = [-1 for _ in xrange(size)]

  def find(self, x):
    while self.table[x] >= 0: x = self.table[x]
    return x

  def union(self, x, y):
    s1 = self.find(x)
    s2 = self.find(y)
    if s1 != s2:
      if self.table[s1] >= self.table[s2]:
        self.table[s1] += self.table[s2]
        self.table[s2] = s1
      else:
        self.table[s2] += self.table[s1]
        self.table[s1] = s2
      return True
    return False

def hash(n, s, g):
  return n*s+g

def dehash(n, hs):
  return [(hs-hs%n)/n, hs%n]

def kruskal(n, path):
  path = sorted(path.items(), key=lambda x:x[1])
  selected = {}
  union = UnionFind(n)
  for i in xrange(len(path)):
    k,v = path[i]
    s,g = dehash(n, k)
    if union.union(s, g):
      selected[k] = v
  return selected

# main
while True:
  n = int(raw_input())
  if n==0:
    break
  m = int(raw_input())
  path = {}
  for _ in xrange(m):
    a,b,d = map(int, raw_input().split(","))
    path[hash(n, a, b)] = d/100-1
  result = kruskal(n, path)
  sumdist = 0
  for v in result.values():
    sumdist += v
  print sumdist

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

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define sq(x)           ((x)*(x))
#define pi              acos(-1.0)
#define NUM             1000005

typedef long long ll;


int main()
{
    FastRead

    string s;
    ll cnt1=0,cnt2=0;
    
    cin>>s;
    
    for(ll i=0; i<s.size(); i++)
    {
        if(i%2==0 && s[i]=='0')
        {
            cnt1++;
        }
        if(i%2==1 && s[i]=='1')
        {
            cnt1++;
        }
    }
    
    for(ll i=0; i<s.size(); i++)
    {
        if(i%2==1 && s[i]=='0')
        {
            cnt2++;
        }
        if(i%2==0 && s[i]=='1')
        {
            cnt2++;
        }
    }
    
    cout<<min(cnt1,cnt2)<<endl;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    int arr[m+1] = {0};
    for(int i=0; i<n; i++){
        int temp;
        cin >> temp;
        for(int j=0; j<temp; j++){
            int k;
            cin >> k;
            arr[k-1]++;
        }
    }
    int cntr = 0;
    
    for(int i=0; i<m+1; i++){
        if(arr[i] == n) cntr++;
    }
    cout << cntr;
    return 0;
}

Measured memory_bytes: 256
# ABC 135: B – 0 or 1 Swap
n = int(input())
p = [int(s) for s in input().split()]

p_sorted = sorted(p)

difference = 0
same = len(p) - len(set(p))

for i in range(n):
    if p[i] != p_sorted[i]:
        difference += 1

print('YES' if same > 0 or difference <= 2 else 'NO')

Measured memory_bytes: 3064
# ABC141D - Powerful Discount Tickets
from heapq import heapify, heappop, heappush


def main():
    N, M, *A = map(int, open(0).read().split())
    B = [-i for i in A]
    heapify(B)
    for _ in range(M):
        x = -heappop(B) // 2
        heappush(B, -x)
    ans = -sum(B)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14180
#include<bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl '\n'
#ifndef CODE_JAM
#undef CASE_INFO
#endif
#else
#pragma GCC optimize "trapv"
#endif
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(n) for(int i = 0; i < n; i++)
#define repj(n) for(int j = 0; j < n; j++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
template<class X=int>inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int>inline X len(X s,X e){return (e-s+1);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int oo = 987654321;
const ll OO = 1e18;

class Timer {
public:
	clock_t start;
	Timer() { start = clock(); }
	~Timer() { cerr << (double)(clock() - start)/CLOCKS_PER_SEC << "\n";}
};

void solve() {
	int k;
	cin >> k;
	set<int> s;
	int cur = 7 % k;
	int steps = 1;
	s.insert(cur);
	while(1) {
		if(cur == 0) {
			cout << steps << endl;
			return;
		}
		cur = ((cur * 10) + 7) % k;
		if(cur != 0 and s.count(cur)) {
			cout << "-1\n";
			return;
		}
		s.insert(cur);
		steps++;
	}
}

signed main() {
	Timer ti;
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int T = 1;
	#ifdef TEST_CASES
	cin >> T;
	#endif
	for(int t = 1; t <= T; t++) {
		#ifdef CASE_INFO
		cout << "Case #" << t << ": ";
		#endif
		solve();
	}
	return 0;
}


Measured memory_bytes: 50668
#include <bits/stdc++.h>
using namespace std;
int main() {
  int Q;
  cin >>Q;
  int a[100001];
  a[0]=0;
  a[1]=0;
  a[2]=0;
  for(int i=3; i<100000; i++){
	bool finish = false;
    a[i]=0;
    for(int j=2; j<=i/j; j++){
      if(i%j==0){
        finish=true;
        break;
      }
    }
    for(int j=2; j<=(i+1)/2/j; j++){
      if(((i+1)/2)%j==0 || finish==true){
        finish=true;
        break;
      }
    }
    if(finish==false)
      a[i]=1;
  }
  for(int i=0; i<100000; i++)
    a[i+1] = a[i]+a[i+1];
  for(int i=0; i<Q; i++){
    int l,r;
    cin >>l >>r;
    cout <<a[r]-a[l-1] <<endl;
  }
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn=510,maxL=10000010,inf=0x3f3f3f3f;
struct cyc{int v,flow,from;}e[maxn*maxn*2];
int tot=1,cnt,n,first[maxn],d[maxn],S,T,num[maxn],b[maxn],cur[maxn];
bool c[maxL];
inline int ab(int x){return x>0?x:-x;}
bool isprime(int x){
    if(x<=2)return 0;
    for(int i=2;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
void insert(int u,int v,int w){
    tot++;e[tot].v=v;e[tot].flow=w;e[tot].from=first[u];first[u]=tot;
    tot++;e[tot].v=u;e[tot].flow=0;e[tot].from=first[v];first[v]=tot;
}
queue<int>q;
bool bfs(){
    memset(d,-1,sizeof(d));
    q.push(S);d[S]=0;
    while(!q.empty()){
        int x=q.front();q.pop();
        for(int i=first[x];i;i=e[i].from)
        if(d[e[i].v]==-1&&e[i].flow){
            d[e[i].v]=d[x]+1;
            q.push(e[i].v);
        }
    }
    return d[T]!=-1;
}
int dinic(int x,int a){
    if(x==T||a==0)return a;
    int f,flow=0;
    for(int& i=cur[x];i;i=e[i].from)
    if(d[e[i].v]==d[x]+1&&e[i].flow&&(f=dinic(e[i].v,min(a,e[i].flow)))>0){
        e[i].flow-=f;
        e[i^1].flow+=f;
        a-=f;
        flow+=f;
        if(a==0)break;
    }
    return flow;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){scanf("%d",&num[i]);c[num[i]]=1;}
    for(int i=1;i<=maxL-5;i++)if(c[i]!=c[i-1])b[++cnt]=i;
    S=0;T=cnt+1;
    int m1=0;
    for(int i=1;i<=cnt;i++)if(b[i]&1){
        m1++;
        insert(S,i,1);
        for(int j=1;j<=cnt;j++)if(!(b[j]&1)&&isprime(ab(b[i]-b[j])))insert(i,j,1);
    }else{
        insert(i,T,1);
    }
    int ans=0;
    while(bfs()){
        for(int i=S;i<=T;i++)cur[i]=first[i];
        ans+=dinic(S,inf);
    }
    printf("%d",cnt-ans+(m1-ans)%2);
    return 0;
}

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

#define rep(i, n) for(int i=0; i < (n); ++i)
#define ll long long

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

    int x, y; cin >> x >> y;
    mint ans = 0;

    if ((2 * x - y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int m = (2*x - y) / 3;
    int n = x - 2 * m;

    combination c(m+n);
    ans = c(m+n, m);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10752
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){

  string S; cin >> S;

  vector <char> Schar;
  map <char, int> charmap;
  
  for (int i = 0; i < S.length(); i++){
    if (charmap[S[i]] == 0){
      Schar.push_back(S[i]);
    }
    charmap[S[i]]++;
  }
  
  int ans = S.length();
  if (charmap[S[0]] == S.length()){
    ans = 0;
  }
  

  for (int i = 0; i < Schar.size(); i++){
    char change = Schar[i];

    string T = S;
    bool flag = false;
    
    int cnt = 1;
    while (flag == false){
      flag = true;
      string T_new;
      for (int j = 0; j < T.length() - 1; j++){
        if (T[j] != change && T[j + 1] != change){
          flag = false;
          T_new += T[j];
        }else{
          T_new += change;
        }
      }

      if (flag == true){
        if (cnt < ans) ans = cnt;
      }else{
        cnt ++;
        T = T_new;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PRECISION(x) cout << fixed << setprecision(x); 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(i,n) for (int i = 0; i < n; ++i)
#define DO(X) while(X--)
#define DRI(X) int (X); cin >> X
#define DRII(X, Y) int X, Y; cin >> X >> Y
#define DRIII(X, Y, Z) int X, Y, Z; cin >> X >> Y >> Z
#define read(X) for(int &ele : (X)) cin >> ele
#define readI(X) for(int idx = 1; idx < SZ((X)); ++idx) cin >> (X)[idx]
#define debug(x) cerr << '>' << #x << ':' << x << endl
#define MP make_pair
#define PB push_back
#define F first
#define S second

using namespace std;
typedef long long LL;
const int INF = 1<<29;
inline int in() { int x; cin >> x; return x; }
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }

int main(){
	FAST_IO 
	DRII(N, K);
	vector<int> gain(3);
	vector<vector<int>> group(K);
	REP(rep, 3) cin >> gain[rep];
	string moves; cin >>  moves;
	for(int idx = 0; idx < N; ++idx) group[idx % K].push_back(idx);
	int maxProfit = 0;
	auto winning = [&](char a, char b){
		if(a == 'r' && b== 's'){
			return gain[0];
		}
		if(a == 's' && b == 'p'){
			return gain[1];
		}
		if(a == 'p' && b == 'r'){
			return gain[2];
		}
		return 0;
	};
	for(int modF = 0; modF < K; ++modF){
		int M = SZ(group[modF]);
		vector<vector<int>> curProfit(M, vector<int>(3));
		for(int idx = 0; idx < M; ++idx){
			curProfit[idx][0] = (idx > 0 ? max(curProfit[idx - 1][1], curProfit[idx - 1][2]) : 0)
								+ winning('r', moves[group[modF][idx]]); 
			curProfit[idx][1] = (idx > 0 ? max(curProfit[idx - 1][0], curProfit[idx - 1][2]) : 0)
								+ winning('s', moves[group[modF][idx]]); 
			curProfit[idx][2] = (idx > 0 ? max(curProfit[idx - 1][1], curProfit[idx - 1][0]) : 0)
								+ winning('p', moves[group[modF][idx]]); 
		}
		maxProfit += max({curProfit[M - 1][0], curProfit[M - 1][1], curProfit[M - 1][2]});
	}
	cout << maxProfit << endl;
	return 0;
}

Measured memory_bytes: 6216
#include <bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
    // a + b + 2 * sqrt(a * b) < c
    //
    cin>>a>>b>>c;
    if (c-a-b>0&&4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e15+7;
const ll N = 100001;

int main(){
	string s;
	cin>>s;
	if( (s[0]==s[1]&&s[1]==s[2]) || (s[1]==s[2]&&s[2]==s[3]) ){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256