akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<unordered_map>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define pii                 pair<int,int>
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define forr(i, n) for (int i = 0; i < int(n); i++)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 1e7 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
void mansour()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin) ;
    freopen("output.txt" , "w" , stdout) ;
#endif
}
ll mem[100005],n,a[100005],k;
ll min_path(int ix)
{
	if(ix>=n)
		return 1e10;
	if(ix==n-1)
		return 0;
	if(mem[ix]!=-1)
		return mem[ix];
	ll r=1e10;
	for(int i=1;i<=k;i++)
	{
		if(ix+i<n)
			r=min(r,min_path(ix+i)+abs(a[ix]-a[ix+i]));
	}
	return mem[ix]=r;
}
int main()
{
	mansour();
	//file();
	/*The First*/
	memset(mem,-1,sizeof(mem));
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	cout <<min_path(0)<<"\n";
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0; i<n; i++)
#define fof(i,s,e) for(int i=s; i<e; i++)
#define fob(i,e,s) for(int i=e; i>=s; i--)

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define all(v) (v).begin(),(v).end() 
#define arl(v) (v).rbegin(),(v).rend() // from right
#define vmn(a) (*min_element(a.begin(),a.end())) // vector min   
#define vmx(a) (*max_element(a.begin(),a.end())) // vector max
#define MOD 1000000007
typedef long long ll;
typedef map<int, int> mi;
typedef unordered_map<int, int> umi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//-----------------------------------------------------------------------------

bool isPossible(const int a, const int b, const int c) {
    if(a==b||b==c||c==a) return false;
    if(!(a+b>c && b+c>a && c+a>b)) return false;

    return true;
}

void code(){

    int n;
    cin>>n;

    vi v(n);

    fo(i,n) cin>>v[i];
    int ans = 0;
    fof(i,0,n-2) {
        fof(j,i+1,n-1) {
            fof(k,j+1, n) {
                if(isPossible(v[i],v[j],v[k])) ans++;
            }
        }
    }
    cout<<ans;
}

// ------------------------------------------------------------------------------

int main(){
    IOS;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        
    int t=1;
    // cin>>t;
    fo(i,t) {
        //cout<<"Case #"<<i+1<<" :";
        code();
    }

    return 0;
}

Measured memory_bytes: 3628
#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 double eps = 1E-18;

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 operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return 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;
	}
};

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



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

	vector<ll> s(N + 1);
	repn(i, N) cin >> s[i];

	ll mx = 0;
	while (mx*mx*mx < 1e10) {
		mx++;
	}

	
	for(ll i=2; i<=mx; i++) {
		ll x = i * i*i;

		repn(j, N) {
			while (s[j] % x == 0) { s[j] /= x; }
		}
	}

	vector<ll> tmp(N + 1);
	repn(i, N) tmp[i] = s[i];

	vector<ll> p(N+1,1);//s[i]と組になるもの(自分より大)
	for (ll i = 1; i <= mx; i++) {
		repn(j, N) {
			if (tmp[j] % (i*i) == 0) {
				tmp[j] /= i * i;
				p[j] *= i;
			}
		}
	}

	repn(j, N) {
		p[j] *= tmp[j] * tmp[j];
	}
	
	map<ll, ll> cube;
	repn(i, N) cube[s[i]] = p[i];

	map<ll, ll> mp;
	repn(i, N) mp[s[i]]++;

	ll ans = 0;

	for (auto p : mp) {
		ll x = p.first;
		if (x == 1) { ans++; }
		else if (mp[x] != 0) { ans += max(mp[x], mp[cube[x]]); mp[cube[x]] = 0; }
		else { ans += mp[x]; }

		//cout << x << " " << mp[x] << " " << cube[x] << endl;
	}

	cout << ans << endl;


	system("PAUSE");
}


Measured memory_bytes: 21624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>

using namespace std;

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

typedef long long ll;

int main(){
	int a, b, c;
	
	cin >> a >> b >> c;
	
	int cnt = 3;
	
	if (a == b) cnt--;
	if (a == c) cnt--;
	if ((a != b || a != c) && b == c) cnt--;
	
	cout << cnt << endl;
	
	return 0;
}

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

int cal(int n) {
  int sum=0;
  while(n>0) {
    sum +=n%10;
    n /=10;
  }
  return sum;
}

int main (void) {
  int N, A, B;
  cin >> N;
  int x = cal(N);
  if (N%x == 0 ){
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 256
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	El3zba;
	int n;
	cin >> n;
	vector<int>a(n);
	int ans = 0;
	int mx = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
	{
		if (a[i] <= a[i-1])
		{
			ans++;
		}
		else {
			mx = max(ans, mx);
			ans = 0;
		}
	}
	mx = max(ans, mx);
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<Edge>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,M;
  cin>>N>>M;
  Graph G(N);
  ll L[M],R[M],D[M];
  REP(i,M){
    cin>>L[i]>>R[i]>>D[i];
    L[i]--,R[i]--;
    G[L[i]].PB(Edge(R[i],D[i]));
    G[R[i]].PB(Edge(L[i],-D[i]));
  }
  
  bool CAN=true;
  ll X[N];
  REP(i,N) X[i]=INF;
  
  REP(i,N){
    if(X[i]!=INF) continue;
    
    queue<int> Q;
    Q.push(i);
    X[i]=0;
    
    while(!Q.empty()){
      ll v=Q.front();
      Q.pop();
      FORE(nv,G[v]){
        if(X[nv.first]!=INF){
          if(X[nv.first]!=X[v]-nv.second) CAN=false;
        }
        else{
          X[nv.first]=X[v]-nv.second;
          Q.push(nv.first);
        }
      }
    }
    
  }
  
  if(CAN) COYe;
  else CONo;
  return 0;
}

Measured memory_bytes: 21704
#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(){
    string s; cin >> s;
    int n = s.size();
    int ai = -1, zi;

    rep(i,n){
        if(s[i] == 'A'){
            if(ai == -1){
                ai = i;
            }
        }
        if(s[i] == 'Z'){
            zi = i;
        }
    }

    cout << zi - ai + 1 << endl;
}

Measured memory_bytes: 640
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const int M=1000000007;
const int MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=5e5+5;


ll f(ll a,ll b){
  ll c=0;
  while(a||b){
    a/=10;
    b/=10;
    c++;
  }
  return c;
}


int main()
{ 

IOS;


ll a,b,x;
cin>>a>>b>>x;

a+=(x-a%x)%x;

b-=b%x;

if(a>b){
  cout<<0<<endl;
  return 0;
}

cout<<(b-a)/x+1<<endl;


//end_routine();

return 0;
 
}


Measured memory_bytes: 3652
package main

import "fmt"

type Pair struct {
        First  int64
        Second int64
}

func prime_factorize(n int64) []Pair {
        res := make([]Pair, 0, 0)

        var p, num int64

        for p = 2; p*p <= n; p++ {
                if n%p != 0 {
                        continue
                }
                num = 0
                for n%p == 0 {
                        num++
                        n /= p
                }
                res = append(res, Pair{First: p, Second: num})
        }
        if n != 1 {
                res = append(res, Pair{First: n, Second: 1})
        }
        return res
}

// n! の約数の数を mod で割った余りを返す
func mod_div_fact(n, mod int64) int64 {
        var i int64
        mp := make(map[int64]int64)

        for i = 2; i <= n; i++ {
                s := prime_factorize(i)
                for _, value := range s {
                        p := value.First
                        e := value.Second
                        mp[p] += e
                }
        }
        var ret int64 = 1
        for key, value := range mp {
                if key == 1 {
                        continue
                }
                ret *= (value + 1)
                ret %= mod
        }
        return ret
}

func main() {
        var n int64
        var mod int64 = int64(1e9) + 7

        fmt.Scan(&n)

        fmt.Println(mod_div_fact(n, mod))
}

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

using namespace std;
using ll = long long;

int K;

template<class T>
struct Vector {
  vector<T> v;
  Vector(int sz) : v(sz, 0) {}
  Vector() : v(0) {}
  Vector(vector<T> t) : v(t) {}
  auto& operator[](size_t pos) {
    return v[pos];
  }
  auto begin() {
    return v.begin();
  }
  auto end() {
    return v.end();
  }
  auto size() {
    return v.size();
  }
  auto push_back(T t) {
    v.push_back(t);
  }
  auto pop_back() {
    v.pop_back();
  }
  auto& back() {
    return v.back();
  }
  friend auto& operator>>(istream& lhs, Vector& rhs) {
    for (int i = 0; i < rhs.size(); i++) lhs >> rhs[i];
    return lhs;
  }
  friend auto& operator<<(ostream& lhs, Vector& rhs) {
    for (int i = 0; i + 1 < rhs.size(); i++) lhs << rhs[i] << endl;
    if (rhs.size()) lhs << rhs.back();
    return lhs;
  }
};

Vector<ll> calc(Vector<ll>& x, Vector<ll>& y)
{
  Vector<ll> res;
  for (ll X : x) {
    for (ll Y : y) {
      res.push_back(X + Y);
    }
  }
  sort(res.begin(), res.end(), greater<ll>());
  while (res.size() > K) res.pop_back();
  return res;
}

int main()
{
  int x, y, z;
  cin >> x >> y >> z >> K;
  Vector<ll> a(x), b(y), c(z);
  cin >> a >> b >> c;
  auto v = calc(a, b);
  v = calc(v, c);
  cout << v << endl;
}


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

int main() {

  int A, B;
  cin >> A >> B;

  int p, m, k;

  p = A + B;
  m = A - B;
  k = A * B;

  if (p >= m && p >= k) {
    cout << p << endl;
  } 
  if (m > p && m >= k) {
    cout << m <<endl;
  }
  if (k >p && k > m) {
    cout << k << endl;
  }

} 

Measured memory_bytes: 256
#include <cstdio>


int k, l;
int a[200];
int main() {
	// freopen("b.in", "r", stdin);
	while (scanf("%d%d", &k, &l) != EOF) {
		int max_num = 0;
		for (int i = 0; i < l; i++) {
			scanf("%d", &a[i]);
			if (a[i] > max_num) {
				max_num = a[i];
			}
		}
		if (max_num * 2 <= k) {
			puts("0");
		} else {
			printf("%d\n", max_num - ((k - max_num)+1));
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int Linearsearch(int *,int,int);

int main(){
  int i,j=0,n,q;
  int S[10000+1],T[10000+1];

  scanf("%d",&n);

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

  scanf("%d",&q);

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

for(i=0;i<q;i++){
if(Linearsearch(S,n,T[i])==1)j++;
}

printf("%d\n",j );
}


int Linearsearch(int S[],int n,int key){
  int i;

  for(i=0;i<n;i++){
    if(S[i] == key)return 1;
  }
  return 0;
}


Measured memory_bytes: 2128
#include <iostream>
#include <stdio.h>
using namespace std;
int n, k, h[100005], ans;
int main() {
	cin >> n >> k;
	for(int i= 1; i <= n; i++) {
		cin >> h[i];
		if(h[i] >= k) ++ans;
	}
	cout << ans << endl;
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    ll ans = 0;
    if (llabs(x)/d>=k) {
        ans = llabs(x) - (k*d);
    }
    else {
        k -= llabs(x)/d;
        ll x2 = llabs(x)%d;
        if (k%2==0) ans = x2;
        else ans = d - x2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

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

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

using namespace std;

int main(int argc, char const *argv[])
{
    vector<bool> alfa(26,true);
    string S;

    cin>>S;


    for(int i=0;i<S.size();++i){
        alfa[S[i]-'a']=false;
    }


    for(int i=0;i<26;++i){
        if(alfa[i]){ 
            cout<<char(i+'a')<<endl;
            return 0;
        }
    }

    cout<<"None"<<endl;

    return 0;
}

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

#define mp make_pair
#define pb push_back
#define f first
#define s second

using namespace std;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	string s;
	cin>>s;
	if(s.size()%2==1) {
		cout << "No\n";
		return 0;
	}
	int last = 0;
	for (int i = 0; i < s.size(); i ++) {
		if (last == 0) {
			if (s[i] != 'h') {
				cout << "No\n";
				return 0;
			}
			last = 1; 
		}
		else {
			if (s[i] != 'i') {
				cout << "No\n";
				return 0;
			}
			last = 0;
		}
	}
	
	cout << "Yes\n";
}


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

const ll NMAX = 2e5 + 5;
ll N;
vector<vector<ll>> G(NMAX);
vector<ll> color(NMAX, 0);

void dfs(int c) {
  for (ll n: G[c]) {
    if (color[n]) continue;
    color[n] = 3 - color[c];
    dfs(n);
  }
}

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

  cin >> N;
  for (ll i = 0; i < N - 1; i++) {
    ll a, b; cin >> a >> b; a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  color[0] = 1;
  dfs(0);

  ll count1 = 0, count2 = 0;
  for (ll i = 0; i < N; i++) {
    if (color[i] == 1) count1++; else count2++;
  }

  ll x1 = 1, x2 = 2, x3 = 3;
  vector<ll> ans(N, 0);
  if (count1 <= N / 3 || count2 <= N / 3) {
    ll myColor = 1;
    if (count2 <= N / 3) myColor = 2;

    for (ll i = 0; i < N; i++) {
      if (color[i] == myColor) {
        ans[i] = x3;
        x3 += 3;
      } else if (x1 <= N) {
        ans[i] = x1;
        x1 += 3;
      } else if (x2 <= N) {
        ans[i] = x2;
        x2 += 3;
      } else {
        ans[i] = x3;
        x3 += 3;
      }
    }
  } else {
    for (ll i = 0; i < N; i++) {
      if (color[i] == 1 && x1 <= N) {
        ans[i] = x1;
        x1 += 3;
      } else if (color[i] == 2 && x2 <= N) {
        ans[i] = x2;
        x2 += 3;
      } else {
        ans[i] = x3;
        x3 += 3;
      }
    }
  }
  cout << ans[0]; for (int i = 1; i < ans.size(); i++) { cout << ' ' << ans[i]; }

  return 0;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
#define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll n,W;
    cin>>n>>W;
    ll w[n+1];
    ll v[n+1];
    for (int i = 1; i<=n; ++i)
    {
        cin>>w[i];
        cin>>v[i];
    }
    ll max_v = n*1010;
    ll dp[n+1][max_v+1];

    for (int i = 0; i < n+1; ++i)
    {
        for (int j = 0; j < max_v+1; ++j)
        {
            dp[i][j]=inf;
        }
    }

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

    for (int i = 1; i < n+1; ++i)
    {
        for (int j = 1; j < max_v+1; ++j)
        {
            dp[i][j]=dp[i-1][j];
            if((j-v[i])>=0){
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]]+w[i]);
            }
        }
    }

    ll ans=0;
    for (int i = 1; i<max_v+1; ++i)
    {
        if(dp[n][i]!=inf){
            if(dp[n][i]<=W){
                ans=max(ans, i);
            }
        }
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 80000
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,prev, next;
    int a[110000];
    int cnt=0,sum=0;
    bool flg;
    cin >> n;
    a[0] = 0;
    for(int i=0; i<n; i++){
        cin >> a[i+1];
    }
    a[n+1] = 0;
    for(int i=0; i<n+1; i++){
        sum += abs(a[i] - a[i+1]);
    }
    for(int i=1; i<n+1; i++){
        cnt = sum;
        prev = a[i-1];
        next = a[i+1];
        flg = (prev - next <0)? true:false;
        if(!flg){
            if(!((a[i] <= prev && a[i]>= next))){
                cnt -= 2*((abs(prev - a[i]) < abs(next -a[i]))?abs(prev - a[i]):abs(next - a[i]));
            }
        }else{
            if(!((a[i] >= prev && a[i]<= next))){
                cnt -= 2*((abs(prev - a[i]) < abs(next -a[i]))?abs(prev - a[i]):abs(next - a[i]));
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <map>
#define for1(x,y) for(long long x = 1; x<ll(y); x++)
#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
#define PII pair<int,int>
#define FF first
#define SS second
#define PB push_back
#define all(x) x.begin(), x.end()

#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
using namespace std;
typedef long long ll;
typedef long double ld;	
#define vi vector<int> 
#define vl vector<ll> 
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define maxn 1000015
const double EPS = (1e-7), EPSm= (1e7);
const ll linf = (ll)1e17 + 5;
long double PI = 3.14159265359;
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{-1,-1},{1,1},{-1,1},{1,-1}};
	
const int MAXN = 3*1e5+10;
const int NINF = -1e5;
const int INF = 20000000;

  
  
void solve()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(a*c,max(a*d,max(b*c,b*d)))<<endl;
	return;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int test;
	//cin >> test;
	//while(test--)
		solve();
	return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a[3];
    for(int i=0;i<3;i++)cin>>a[i];
    sort(a,a+3);
    cout<<a[0]+a[1];
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
int main(){
  FIO;
  // ifstream cin("input");
  string a;
  cin>>a;
  for(int i=0;i<a.size();i++){
    if(a[i]=='7'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;  
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){

    const int MAX = 1000001;
    int n, tmp;
    cin >> n;
    vector<int> num_count(MAX, 0);
    vector<bool> num_bool(MAX, false);
    int ans = 0;
    rep(i,n){
        cin >> tmp;
        num_count[tmp]++;
        num_bool[tmp] = true;
    }
    for(int i = 1; i < MAX; i++) {
        if (!num_bool[i]) continue;
        if (num_count[i] == 1) ans++;
        for(int j = i; j < MAX; j += i) {
            num_bool[j] = false;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7220
import sys
from heapq import *
input = sys.stdin.readline


def solve(n, k, p):
    res = n-k+1
    count = 0
    length = 1
    
    judge_max = [-x for x in p[:k]]
    judge_min = p[:k]
    heapify(judge_max)
    heapify(judge_min)
    already = [False]*n
    
    for i in range(k-1):
        if p[i] < p[i+1]:
            length += 1
        else:
            length = 1
            
    if length == k:
        count += 1
    
    for i in range(k-1, n-1):
        if p[i] < p[i+1]:
            length += 1
        else:
            length = 1
        
        already[p[i-k+1]] = True
        while True:
            vmax = -judge_max[0]
            if already[vmax]:
                heappop(judge_max)
                continue
            else:
                break
        while True:
            vmin = judge_min[0]
            if already[vmin]:
                heappop(judge_min)
                continue
            else:
                break
        if p[i-k+1] < vmin and vmax < p[i+1]:
            res -= 1
        
        elif length >= k:
            if count:
                res -= 1
            count += 1
        heappush(judge_max, -p[i+1])
        heappush(judge_min, p[i+1])
    
    return res

    
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    
    ans = solve(n, k, p)
    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 111888
#include <iostream>
#include <string>
#include <math.h>
using namespace std;


int main(){
    string S;
    cin >> S;
    int n = S.length()-1;
    int n2 = pow(2, n);
    bool plus[n2][n];
    int b;
    for(int i=0;i<n;i++){
        b = pow(2, i);
        for(int j=0;j<n2/b;j++){
            for(int k=0;k<b;k++){
                if(j%2 == 0) plus[j*b+k][i] = false;
                else plus[j*b+k][i] = true;
            }
        }
    }
    long ans=stol(S);
    for(int i=1;i<n2;i++){
        //cout << "i= "<<i<<endl;
        int tmp=0;
        for(int j=0;j<n;j++){
            if(plus[i][j]){
                //cout << "substruct from "<<tmp<<" to "<<j;
                ans += stoi(S.substr(tmp, j+1-tmp));
                //cout << "   "<<stoi(S.substr(tmp, j+1-tmp))<<endl;
                tmp = j+1;
            }

        }
        //cout << "last substruct from "<<tmp<<" to "<<n;
        ans += stoi(S.substr(tmp, n+1-tmp));
        //cout << "   "<<stoi(S.substr(tmp, n+1-tmp))<<endl;
    }
    cout << ans << endl;
}

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

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(string, S);
    string ans = "No";

    if ( S[0] == S[1] && S[2] == S[3] && S[0] != S[2] ) {
        ans = "Yes";
    }
    else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1])
    {
        ans = "Yes";
    }
    else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1])
    {
        ans = "Yes";
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#define INF 0x3f3f3f3f
#define lowbit(x) x & -x
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=3e5+5;
int fx[N],fy[N];
int x[N],y[N];
int main(){
#ifdef Mizp
    freopen("in.txt","r",stdin);
#endif
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=k;i++){
        scanf("%d%d",&x[i],&y[i]);
        fx[x[i]]++;
        fy[y[i]]++;
    }
    int maxx=0,maxy=0;
    for(int i=1;i<=n;i++){
        maxx=max(fx[i],maxx);
    }
    for(int i=1;i<=m;i++){
        maxy=max(fy[i],maxy);
    }
    int flag=0;
    for(int i=1;i<=k;i++){
        if(fx[x[i]]==maxx && fy[y[i]]==maxy)
            flag++;

    }
    int cntx=0,cnty=0;
    for(int i=1;i<=n;i++){
        if(maxx==fx[i])
            cntx++;
    }
    for(int i=1;i<=m;i++){
        if(maxy==fy[i])
            cnty++;
    }
    if(flag==1ll*cntx*cnty)
        printf("%d\n",maxx+maxy-1);
    else 
        printf("%d\n",maxx+maxy);
    return 0;
}


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

int32_t main() {
  int h, n;
  cin >> h >> n;
  int sum = 0;
  while(n--) {
    int x;
    cin >> x;
    sum += x;
  }
  cout << (sum >= h ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include <set>

#define DIV 1000000007
using namespace std;
using ll = long long;

int lcd(int p, int q) {
    int upper, lower, r;

    if (p >= q) upper = p, lower = q;
    else upper = q, lower = p;
    r = upper % lower;
    if (r)return lcd(lower, r);
    else return lower;
}

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

    int mx = -1;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        mx = max(mx, a[i]);
    }

    if (N == 1) {
        if (K == a[0] || K == 0)
            cout << "POSSIBLE" << endl;
        else
            cout << "IMPOSSIBLE" << endl;
    }

    else {
        int lcn = lcd(a[0], a[1]);
        for (int i = 2; i < N; i++) 
            lcn = lcd(lcn, a[i]);
        
        if (K % lcn == 0 && K <= mx)
            cout << "POSSIBLE" << endl;
        else
            cout << "IMPOSSIBLE" << endl;

    }
    
}


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

int main(){
    int N,D;
    scanf("%d %d",&N,&D);
    int x[N][D];
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            scanf("%d",&x[i][j]);
        }
    }
    int count=0;
    double dist;
    for(int i=0;i<(N-1);i++){
        dist=0.0;
        for(int j=i+1;j<N;j++){
            dist=0.0;
            //x[i]とx[j]の距離distを求める
            for(int k=0;k<D;k++){
                //printf("%f\n",pow((x[i][k]-x[j][k]),2));
                dist+=pow((x[i][k]-x[j][k]),2);
            }
            dist=sqrt(dist);
            //printf("%f %f\n",dist,ceil(dist));
            if(dist==ceil(dist)){
                count++;
            }
        }
    }

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

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
  int i,a=0,b=0,c=0;
  char str[8];
  
  fgets(str,sizeof(str),stdin);
  
  for(i=0;i<3;i++)
  {
    switch (str[i])
    {
      case 'a': a++;
    			continue;
      case 'b': b++;
                continue;
      case 'c': c++;
                continue;
    }
  }
  
  if(a*b*c == 1)
  {
    puts("Yes");
  }else
  {
    puts("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextLong();
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        if(A==0){
            System.out.println(0);
            return;
        }
        long num = N/(A+B);
        long rem = N - num*(A+B);
        long remB = rem>=A?A:rem;
        System.out.println(num * A + remB);
    }

}


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

int N,maxn=1;

int main(){
	cin>>N;
	for(int i=2;i<=10000;i++){
		int f=i*i;
		while(f<=N){maxn=max(maxn,f);f*=i;}
	}
	cout<<maxn<<endl;
	return 0;
}


Measured memory_bytes: 256
use proconio::input;

#[proconio::fastout]
fn main() {
    input! {
        n: usize
    }

    let m: i64 = 1000000007;
    let mut dp: Vec<i64> = vec![0; n + 1];
    dp[0] = 1;

    for k in 0..n {
        let mut dp2 = vec![0; n + 1];
        dp2[n] = dp[n];
        for i in (3 * k)..(n + 1) {
            for j in (3..(n + 1 - i)).rev() {
                dp2[j + i] += dp[i];
                dp2[j + i] %= m;
            }
        }
        dp = dp2;
    }

    println!("{}", dp[n]);
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a^b^c)<<endl;
}

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

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

    long long n, p;
    cin >> n >> p;
    
    map<long long, long long> mp;

    // 素因数分解
    long long tmp = p;
    for(long long i = 2; i * i <= p; i++){
        // 素因数分解が終わっていたら抜ける
        if(tmp == 1) break;
        while(tmp % i == 0){
            mp[i]++;
            tmp /= i;
        }
    }

    // pの，pの(1/2)乗以下の最大の素因数をカウント
    // ここvalueは必ず1になる
    mp[tmp]++;

    long long ans = 1;
    for(auto x : mp){
        // pの素因数をn個に均等になるべく多く分配する
        for(int i = 0; i < x.second / n; i++){
            ans *= x.first;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] k = new int[n];
        Unionfind uf = new Unionfind(n + m + m);
        for (int i = 0 ; i < n ; i++) {
            k[i] = sc.nextInt();
            for (int j = 0 ; j < k[i] ; j++) {
                int l = sc.nextInt() + n;
                uf.union(i, l);
            }
        }
        Set<Integer> set = new HashSet<>();
        for (int i = 0 ; i < n ; i++) {
            set.add(uf.findRoot(i));
        }
        System.out.println(set.size() == 1 ? "YES" : "NO");
    }

}

class Unionfind {
    ArrayList<Integer> parent;

    public Unionfind(int n) {
        parent = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            parent.add(-1);
        }
    }

    public boolean union(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) {
            return false;
        }

        if (size(x) < size(y)) {
            int temp = x;
            x = y;
            y = temp;
        }

        parent.set(x, parent.get(x) + parent.get(y));
        parent.set(y, x);
        return true;
    }

    public int findRoot(int i) {
        if (parent.get(i) < 0) {
            return i;
        } else {
            int root = findRoot(parent.get(i));
            parent.set(i, root);
            return root;
        }
    }

    public int size(int x) {
        return -parent.get(findRoot(x));
    }

    public boolean same(int x, int y) {
        return findRoot(x) == findRoot(y);
    }
}


Measured memory_bytes: 86560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vi vector<int>
#define sl set<ll>
#define sc set<char>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mpi map<ll,ll>
#define mpc map<char,ll>
#define forn(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inf        10000000


int main()
{
    ll n;
    cin>>n;
    ll a[3];
    ll dp[3]={0};
    forn(i,n)
    {
        forn(j,3)
        {cin>>a[j];}
        ll new_dp[3]={0};
        forn(k1,3)
        {
            forn(k2,3)
            {
                if(k1!=k2)
                {
                    new_dp[k2]=max(new_dp[k2],dp[k1]+a[k2]);
                }
            }
        }
        forn(k1,3)
        dp[k1]=new_dp[k1];
    }
    cout<<max(dp[0],max(dp[1],dp[2]));
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        
        int i = Integer.parseInt(a + b);
        
        if(Math.sqrt(i) % 1 == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

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

int const MAX = 2e5 + 41;

int n;
int a[MAX];

void kill(ll ans) {
	printf("%lld\n", ans);
	exit(0);	
}

int add;
set<int> t;

bool check(int x) {
	if (t.find(x - add) != t.end()) return true;
	return false;
}

void shift() {
	while (sz(t)) {
		int x = (*t.begin());
		if (x + add <= 0) {
			t.erase(t.begin());
		} else {
			break;
		}
	}
}

void push(int x) {
	t.insert(x - add);
}

void solve() {
	if (a[1] != 0) {
		kill(-1);
	}
	fi(2, n) {
		if (a[i] - a[i - 1] > 1) kill(-1);
	}
	ll ans = 0;
	fdi(n, 2) {
		if (a[i] == 0) {
			t.clear();
			add = 0;
			continue;
		}
		add--;
		shift();
		if (!check(a[i])) {
			push(a[i]);			
		}
		ans += sz(t);
		err("i = %d sz = %d\n", i, sz(t));
	}	

	kill(ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	fi(1, n) {
		scanf("%d", &a[i]);
	}
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 5760
#include <cstdio>
#include <functional>
#include <vector>
#include <tuple>

using namespace std;

using ll = long long;
int a[200000];

int main()
{
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &(a[i]));
  }
  ll ops = 0;
  bool failed = false;
  for (int i = n-1; 0 <= i;) {
    int last = i;
    while ((0 <= i-1) && (a[i-1]+1==a[i])) {
      // printf("%d, ", a[i-1]);
      i--;
    }
    // printf("\n");
    if ((1<=i && ((a[i-1]+1)<a[i])) || (a[last] > last)) {
      failed = true;
      break;
    }
    ops += a[last];
    i--;
  }
  if (failed) {
    printf("-1\n");
  }
  else {
    printf("%lld\n", ops);
  }
  return 0;
}


Measured memory_bytes: 896
# D - Not Divisible
N = int(input())
a = list(map(int, input().split()))
a.sort()
MAX = a[-1]
l = [0]*(MAX+1)
for i in range(N):
    l[a[i]] += 1
    
answer = 0
for i in range(N):
    if l[a[i]] == 1:
        answer += 1
    for g in range(a[i], MAX+1, a[i]):
        l[g] = 10
print(answer)

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

int n;
int a[105];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n);
  int sum = 0;
  for (int i = 0; i < n; i++) sum += a[i];
  if (sum % 10) printf("%d\n", sum);
  else {
    for (int i = 0; i < n; i++) {
      if (a[i] % 10) return printf("%d\n", sum - a[i]), 0;
    }
    printf("0\n");
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())

AB = [[0, 0, 0] for i in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    AB[i][0] = a+b
    AB[i][1] = a
    AB[i][2] = b

AB.sort()
ans = 0
for i in range(n):
    _, a, b = AB.pop()
    if i%2 == 0:
        ans += a
    else:
        ans -= b
print(ans)

Measured memory_bytes: 55712
#include <bits/stdc++.h>
#define INF 1000000001
#define MAX 500000
using namespace std;
int N, S[MAX], res;

void Out() {
	cout << S[0];
	for (int i = 1; i < N; i++)
		cout << ' ' << S[i];
	cout << endl;
}

void Merge(int left, int mid, int right) {
	int n1 = mid - left, n2 = right - mid;
	vector<int> L(n1 + 1, INF), R(n2 + 1, INF);
	for (int i = 0; i < n1; i++)
		L[i] = S[left + i];
	for (int i = 0; i < n2; i++)
		R[i] = S[mid + i];
	for (int i = 0, j = 0, k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			S[k] = L[i];
			i++;
		}
		else {
			S[k] = R[j];
			j++;
		}
		res++;
	}
}

void MergeSort(int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		MergeSort(left, mid);
		MergeSort(mid, right);
		Merge(left, mid, right);
	}
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> S[i];
	MergeSort(0, N);
	Out();
	cout << res << endl;
	return 0;
}

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

int main() {
  int n; cin>>n;
  int minmin=1010, mamax=0,a;
  for (int i = 0; i<n; i++) {
    cin>>a;
    minmin=min(minmin,a); mamax=max(mamax,a);
  }
  cout<<mamax-minmin<<endl;
}



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

using namespace std;

const int N = 110,mod=1e9+7;

typedef long long ll;

int a[N];
ll s[110000];
ll f[110][110000];
int main()
{
	ll n,k;
	cin>>n>>k;

	
	memset(f,0,sizeof(f));
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i =0;i<=k;i++) f[1][i] = (i<=a[1])? 1:0;
	for(int i=2;i<=n;i++)
	{	memset(s,0,sizeof(s));
		s[0]=f[i-1][0];
		for(int j=1;j<=k;j++)
		{
			s[j]=s[j-1]+f[i-1][j];
		}
		for(int j=k;j>=0;j--)
		{
			if(j-a[i]-1>=0) f[i][j]=s[j]-s[j-a[i]-1];
			else f[i][j]=s[j];
			f[i][j]%=mod;
		}
	}
	cout<<f[n][k]<<endl;
 
}

Measured memory_bytes: 95616
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>

int main() {
    std :: ios_base :: sync_with_stdio(false);

    int t = 1;
    //std :: cin >> t;

    while(t--) {
        int n;
        std :: cin >> n;

        std :: cout << (n >= 30 ? "Yes\n" : "No\n");
    }
}

Measured memory_bytes: 3688
n,m=map(int,input().split())
a=[]
b=[]

cnt=0
k=0
flag=0
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

for j in range(n-m+1):
    k=0
    for i in range(n-m+1):
        if b[k]==a[i][j:j+m]:
            k+=1
            if k==m:
                print("Yes")
                flag+=1
                break
    else:
        continue
    break


if flag==0:
    print("No")



Measured memory_bytes: 62512
use proconio::input;
use std::collections::HashMap;

const INF:f64 = 1e20;

fn main() {
    input! {
        n:usize,
        xyd:[(i64,i64,char);n]
    };

    let mut dmp = HashMap::<char,(i64,i64)>::new();
    dmp.insert('R',(1,0));
    dmp.insert('L',(-1,0));
    dmp.insert('U',(0,1));
    dmp.insert('D',(0,-1));


    let ts = {
        let mut xyd_sml = Vec::<(i64,i64,char)>::new();
        let dirs = vec!['R','L','U','D'];
        for dir in dirs {
            if let Some(e) = xyd.iter().filter(|&(_,_,d)| dir==*d).max_by_key(|&(x,_,_)|x) {
                xyd_sml.push(*e);
            }
            if let Some(e) = xyd.iter().filter(|&(_,_,d)| dir==*d).min_by_key(|&(x,_,_)|x) {
                xyd_sml.push(*e);        
            }
            if let Some(e) = xyd.iter().filter(|&(_,_,d)| dir==*d).max_by_key(|&(_,y,_)|y) {
                xyd_sml.push(*e);        
            }
            if let Some(e) = xyd.iter().filter(|&(_,_,d)| dir==*d).min_by_key(|&(_,y,_)|y) {
                xyd_sml.push(*e);        
            }
        }

        
        let mut ts = Vec::new();
        for &(x1,y1,d1) in &xyd_sml {
            for &(x2,y2,d2) in &xyd_sml {
                let (dx,dy) = (dmp[&d1].0-dmp[&d2].0,dmp[&d1].1-dmp[&d2].1);
                if dx!=0 {
                    let t = ((x2-x1) as f64)/dx as f64;
                    if 0.0<=t {
                        ts.push(t);
                    }
                }
                if dy!=0 {
                    let t = ((y2-y1) as f64)/dy as f64;
                    if 0.0<=t {
                        ts.push(t);
                    }
                }
            }
        }
        ts
    };

    let calc = |t| {
        let x:Vec<f64> = xyd.iter().map(|&(x,_,d)|{
            let (dx,_) = dmp[&d];
            (x as f64)+(dx as f64)*t
        }).collect();
        let max_x = x.iter().fold(-INF,|m,x| x.max(m));
        let min_x = x.iter().fold(INF, |m,x| x.min(m));
        let y:Vec<f64> = xyd.iter().map(|&(_,y,d)|{
            let (_,dy) = dmp[&d];
            (y as f64)+(dy as f64)*t
        }).collect();
        let max_y = y.iter().fold(-INF,|m,y| y.max(m));
        let min_y = y.iter().fold(INF, |m,y| y.min(m));

        (max_x-min_x)*(max_y-min_y)
    };
    let mut ans = calc(0.0);
    for t in ts {
        ans = ans.min(calc(t));
    }

    println!("{}",ans);
  
    
}




Measured memory_bytes: 8200