akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
 
int main()
{  
	int N=1;
	cin >>N;
 
	bool Yes_Flag=false;
 
	for(int i=0;i<3;i++){
		if(N%10==7){Yes_Flag=true;
		break;
		}
		N/=10;
	} 
 
	if(Yes_Flag){cout<<"Yes"<<endl;}
	else{cout<<"No"<<endl;}
	
	return 0;
}

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

int main(void){
    int N;
    cin >> N;
    int l[1100], r[1100];
    for (int i = 0; i < N; i++) cin >> l[i] >> r[i];
    
    int count = 0;
    for(int i = 0; i < N; i++){
        count += ((r[i]- l[i]) + 1);
    }
    
    cout << count;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



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

	cout << x * x*x << "\n";

	return 0;
}



Measured memory_bytes: 3072
#include <cassert>
#include <cstddef>
#include <tuple>
#include <utility>
#include <vector>

template <class Abelian> class PotentializedUnionFind {

public:
  using value_type = Abelian;
  using size_type = std::size_t;
  using container_type =
      std::vector<std::tuple<size_type, value_type, size_type>>;

protected:
  container_type c;

private:
  size_type &par(const size_type i) { return std::get<0>(c[i]); }
  value_type &val(const size_type i) { return std::get<1>(c[i]); }
  size_type &siz(const size_type i) { return std::get<2>(c[i]); }
  value_type potential(size_type x) {
    value_type ret = {};
    while (x != par(x)) {
      val(x) = val(x) + val(par(x));
      ret = ret + val(x);
      x = par(x) = par(par(x));
    }
    return std::move(ret);
  }

public:
  PotentializedUnionFind() : c() {}
  explicit PotentializedUnionFind(const size_type size)
      : c(size, std::forward_as_tuple(static_cast<size_type>(0), value_type(),
                                      static_cast<size_type>(1))) {
    for (size_type i = 0; i < size; ++i)
      par(i) = i;
  }

  size_type size() const { return c.size(); }
  bool empty() const { return c.empty(); }

  size_type find(size_type x) {
    assert(x < size());
    while (x != par(x)) {
      val(x) = val(x) + val(par(x));
      x = par(x) = par(par(x));
    }
    return x;
  }
  value_type diff(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    assert(same(x, y));
    return potential(y) + (-potential(x));
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return siz(find(x));
  }

  bool unite(size_type x, size_type y, value_type d) {
    assert(x < size());
    assert(y < size());
    d = d + potential(x) + (-potential(y));
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (siz(x) < siz(y))
      std::swap(x, y), d = -d;
    siz(x) += siz(y);
    par(y) = x;
    val(y) = std::move(d);
    return true;
  }
};

#include<iostream>
 
int main() {
	int n, m;
	std::cin >> n >> m;
	PotentializedUnionFind<int> T(n);
	while (m--) {
		int l, r, d;
		std::cin >> l >> r >> d;
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) {
				std::cout << "No" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
struct node{

long long int p,q;

};
bool comp(struct node x,struct node y)
{

    if(x.p<y.p)
        return true;
    else
        return false;
}
int main()

{

    long long int a,b,c,d,i,j,k,l;
    cin>>a>>b;
    struct node n[a];
    for(i=0;i<a;i++)
    {
     cin>>n[i].p>>n[i].q;

    }
    sort(n,n+a,comp);
   long long  int cur=0;
  long long  int price=0;
    for(i=0;i<a;i++)
    {
        if(cur<b)
        {
            k=min(b-cur,n[i].q);
            price+=k*n[i].p;
            cur+=k;
        }
    }
    cout<<price;

}


Measured memory_bytes: 1792
#coding: UTF-8

l = raw_input().split()

W = int(l[0])
H = int(l[1])
x = int(l[2])
y = int(l[3])
r = int(l[4])

if x >=r:
	if y >=r:
		if x <=(H -r):
			if y <=(H-r):
				print "Yes"
			else:
				print "No"
		else:
			print"No"
	else:
		print "No"

else:
	print "No"

Measured memory_bytes: 6448
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    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: 764
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e14 ;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
ll a[100];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	ll min1=a[1];ll ans=1000;
	for(int i=2;i<=n;i++)
	{
		if(a[i]>min1)
		{
			ll sum=ans/min1,result=ans%min1;
			//printf("%d %d %d %d %d\n",a[i],sum,result,ans,min1);
			ans=sum*a[i]+result;
			min1=a[i];
			//printf("%d %d %d\n",sum,result,a[i]);
			//printf("ans: %d\n",ans);
		}
		min1=min(min1,a[i]);
	}
	printf("%lld\n",ans);
	return 0;
} 

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> h(N);
    rep(i, N) cin >> h[i];
    sort(h.rbegin(), h.rend());
    ll ans = h[0]-h[K-1];
    for (int i=1; i<N-K+1; ++i) {
        ans = min(ans, (ll)h[i]-h[i+K-1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;

int main()
{
	int n;
	cin>>n;
	int candy[100][100];
	int *left = new int[n];
	int *right = new int[n];
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < n; j++){
			cin>>candy[i][j];
		}
	}
	left[0] = candy[0][0];
	for(int i = 1; i < n; i++){
		left[i] = candy[0][i] + left[i-1];
	}
	right[n-1] = candy[1][n-1];
	for(int i = n-2; i >= 0; i--){
		right[i] = right[i+1] + candy[1][i];
	}
	int ans = 0;
	rep(i,n){
		ans = max(ans, left[i]+right[i]);
	}
	cout<<ans<<endl;
	return 0;
}



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

int main()
{
	std::uint16_t const bias = 2;
	typedef std::array<std::uint16_t, 10 + 2 * bias> Row;
	typedef std::array<Row, 10 + 2 * bias> Paper;
	Paper paper;

	for (Row& row : paper) {
		row.fill(0);
	}

	std::uint16_t x, y, size;
	char comma;
	while (std::cin >> x >> comma >> y >> comma >> size) {
		enum { Small = 1, Medium, Large };
		x += bias;
		y += bias;

		++paper[x][y];
		++paper[x + 1][y];
		++paper[x - 1][y];
		++paper[x][y + 1];
		++paper[x][y - 1];

		if (size != Small) {
			++paper[x + 1][y + 1];
			++paper[x + 1][y - 1];
			++paper[x - 1][y + 1];
			++paper[x - 1][y - 1];

			if (size == Large) {
				++paper[x + 2][y];
				++paper[x - 2][y];
				++paper[x][y + 2];
				++paper[x][y - 2];
			}
		}
	}

	std::uint16_t num_empty = 0;
	std::uint16_t max_density = 0;
	for (std::uint16_t i = bias; i < 10 + bias; ++i) {
		Row const& row = paper[i];
		num_empty += std::count(row.begin() + 2, row.end() - 2, 0);
		max_density = std::max(
				max_density,
				*std::max_element(row.begin() + 2, row.end() - 2));
	}

	std::cout << num_empty << '\n' << max_density << std::endl;

	return 0;
}

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

using namespace std;
#ifdef ONLINE_JUDGE
#define cerr if(false)cerr
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#define int long long
#define ld1 long double
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout<<setprecision(14);
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
#define mm0(X) memset((X), 0, sizeof((X)))
#define mm1(X) memset((X), -1, sizeof((X)))
#define INF (int)1e9
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define endl '\n'
#define vcc vector<char>
#define rep(i,a,b) for(int i=a;i<b;i++)

// if you have no idea just guess the appropriate well-known algo instead of doing nothing -- Benq inspiration
const int mod=998244353;
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int powmod(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return powmod(a,mod-2);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

const int N=(int)1e6;


void solve(){
    int x,n; cin >> x >> n;
    set<int> s;
    int a[n]; for(int i=0;i<n;i++){
        cin >> a[i];
        s.insert(a[i]);
    }
    sort(a,a+n);

    int minq=INT64_MAX;
    int final=0;
    int beg=0;
    while(s.find(x-beg)!=s.end()) beg++;
    final=x-beg;
    minq=x-final;
    beg=0;
    while(s.find(x+beg)!=s.end()) beg++;
    if(minq>beg){
        final=x+beg;
    }

    cout<<final<<endl;
}

int32_t main() {
    faster;

#ifndef ONLINE_JUDGE
    READ("input.txt");
    WRITE("output.txt");
    double beg=clock();
#endif

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

    while(t--){
        solve();
    }

#ifndef ONLINE_JUDGE
    double endd=clock();
    cout<<endl;
    cerr<<"*** Total time = "<<(endd-beg)/CLOCKS_PER_SEC;
#endif
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n, k;
    cin >> n >> k;
    std::vector<int> a(n);
    int ma = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        chmax(ma, a[i]);
    }
    int gc = a[0];
    for (int i = 1; i < n; i++) {
        gc = gcd(a[i], gc);
    }
    if (k > ma || k % gc != 0) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << "POSSIBLE" << endl;
    }
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  
  int max=0;
  int maxindex=0;
  
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(abs(a)>=abs(max)){
      max=a;
      maxindex=i;
    }
  }
  
  maxindex++;
  
  int m=2*n-1;
  cout<<m<<endl;
  
  if(max>=0){
    for(int i=1;i<=n;i++){
      cout<<maxindex<<" "<<i<<endl;
    }
    for(int i=1;i<n;i++){
      cout<<i<<" "<<i+1<<endl;
    }
  }else if(max<0){
    for(int i=1;i<=n;i++){
      cout<<maxindex<<" "<<i<<endl;
    }
    for(int i=n;i>1;i--){
      cout<<i<<" "<<i-1<<endl;
    }
  }
  


    return 0;
}

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

int main()
{
	int N;cin>>N;
	for(int i=0; i<N; i++)
	{
		string a,b;
		cin>>a>>b;
		if((int)a.length()<=80 && (int)b.length()<=80 )
		{
			while((int)a.length()<81)
				a = "0"+a;
			while((int)b.length()<81)
				b = "0"+b;
			string c(81,'0');
			for ( int i=80; i>=0; i-- )
			{
				int t = a[i]-'0'+b[i]-'0'+c[i]-'0';
				c[i]='0'+t%10;
				if(t>=10)
					c[i-1]=t/10+'0';
			}
			if ( c[0]=='0')
			{
				int p=0;
				while(c[p]=='0')
					p++;
				if(c[p]=='\0')
					cout << "0" <<endl;
				else
					cout<<c.c_str()+p<<endl;
			}
			else
				cout << "overflow" << endl;


		}
		else
			cout << "overflow" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
def main():
    n, m, x = (int(i) for i in input().split())
    a = [int(i) for i in input().split()]
    u=0
    d=0
    for i in range(x+1,n):
        if(i in a):
            u += 1
    for j in range(x-1,0,-1):
        if(j in a):
            d += 1
    if(u<d):
        print(u)
    else:
        print(d)

main()

Measured memory_bytes: 3060
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  1e6+5;
const ll   mod   =  1e9;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, q, a[N], lst[N], ans[N];
vpll Q[N];

ll tree[N] = {};

void update(int idx, int val){ 
    idx++;
    while(idx <= N-2){ 
        tree[idx] += val;
        idx += idx & (-idx); 
    } 
} 

ll query(int idx){
    idx++;
    ll sum = 0;
    while(idx > 0){ 
        sum += tree[idx];
        idx -= idx & (-idx); 
    } 
    return sum; 
}

void solve(){
	cin >> n >> q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 0; i < q; i++){
		int l, r; cin >> l >> r;
		Q[r].pb({l,i});
	}
	for(int i = 1; i <= n; i++){
		update(i,1);
		if(lst[a[i]]) update(lst[a[i]],-1);
		lst[a[i]] = i;
		for(auto it : Q[i]){
			ans[it.s] = query(i)-query(it.f-1);
		}
	}
	for(int i = 0; i < q; i++) cout << ans[i] << "\n";
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 56072
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <stdio.h>
#include <cassert>

#define rep(i, a, b) for (ll i = (a); i <= (b); i++)
#define irep(i, a, b) for (ll i = (a); i >= (b); i--)
#define v(t) vector<int>

using namespace std;
using ll = long long;
using vi = v(int);

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

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

    int N;
    cin >> N;
    vi A(N), prefix(N), suffix(N);
    rep(i,0,N-1) cin >> A[i];
    ll acc=A[0];
    rep(i,0,N-1) {
        acc= gcd(acc, A[i]);
        prefix[i] = acc;
    }
    acc=A[N-1];
    irep(i,N-1,0) {
        acc = gcd(acc, A[i]);
        suffix[i] = acc;
    }
    assert(prefix[N-1] == suffix[0]);
    ll ans=prefix[N-1];
    rep(i,0,N) {
        ll l=1; if (i==0)   l = suffix[i+1]; else l = prefix[i-1];
        ll r=1; if (i==N-1) r = prefix[i-1]; else r = suffix[i+1];
        ans = max(ans, gcd(l, r));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
# include <math.h>
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <algorithm>
# include <iostream>

# define For(i,x,y)   for((i)=(x);i<(y);(i)++)
# define MAX(x,y)   ((x)>(y)? (x):(y))
# define MIN(x,y)   ((x)<(y)? (x):(y))
# define sz(a)      (sizeof(a))
# define mem(a)     (memset((a),0,sizeof(a)))

# define fop freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
# define print(x) (printf("%d\n",x))
# define scan(x) (scanf("%d",&x))
# define printc(x) (printf("%c\n",x))
# define scanc(x) (scanf("%c",&x))
# define INF 0x7fffffff

using namespace std;

typedef long long           ll;
ll c[55][55];
double a[105][55],f[105][55],p[105];
int t[105],v[105];
int main()
{
    int i,j,k,n,m,l,ii,jj;
    double ans,tot,tmp;
    c[0][0]=1;
    for (i=1;i<=50;i++)
      for (j=0;j<=i;j++)
        c[i][j]=c[i-1][j]+c[i-1][j-1];
    scan(n);scan(m);scan(l);
    //print(n);print(m);print(l);
    For(i,1,n+1)
    {
        scanf("%lf",&p[i]);
        p[i]=p[i]/100.0;
        scan(t[i]);scan(v[i]);
    }
    For(i,1,n+1)
      For(j,0,m+1)
      {
          a[i][j]=pow(p[i],j)*c[m][j]*pow(1-p[i],m-j);
          if (v[i])
          {
              f[i][j]=(double)l/(double)v[i];
              f[i][j]+=j*t[i];
          }
          else f[i][j]=INF;
      }
    For (i,1,n+1)
    {
        ans=0;
        For (j,0,m+1)
        {
            tmp=a[i][j];
            For(ii,1,n+1) if (ii!=i)
            {

              tot=0;
              For (jj,0,m+1)
                if (f[i][j]<f[ii][jj])
                  tot+=a[ii][jj];
              tmp*=tot;
            }
            ans+=tmp;
        }
        printf("%.8lf\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1072
import numpy as np
words = lambda t : list(map(t, input().split()))

n = int(input())
h = words(int)

total = 0
for i in range(n):
    v = True
    for j in range(0,i):
        if h[i] < h[j]:
            v = False
            break
    if v:
        total += 1
print(total )


Measured memory_bytes: 21524
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1000000007;

ll facctoria(ll k){
    ll mol=1;
    for (int i=1;i<=k;++i)
    {
        mol*=i;
        mol%=mod;
    }
    return mol;
}
int main(){
	ll n,m;cin>>n>>m;
	ll N=facctoria(n)%mod;
	ll M=facctoria(m)%mod;
	if(abs(n-m)==0){
		cout<<(2*N*M)%mod<<endl;
	}else if(abs(n-m)==1){
		cout<<(N*M)%mod<<endl;
	}else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=200005;
ll tot;
int n,a[N],b[N];
void GG(){
	puts("-1"); exit(0);
}
bool check(){
	For(i,0,n-1)if(a[i]!=b[i])return 0;
	return 1;
}
int main(){
	n=read();
	For(i,0,n-1)a[i]=read();
	For(i,0,n-1)b[i]=read();
	while(!check()){
		For(i,0,n-1)if(a[i]!=b[i]&&b[i]>b[(i+1)%n]&&b[i]>b[(i+n-1)%n]){
			if(a[i]>b[i])GG();
			int x=b[(i+1)%n]+b[(i+n-1)%n],ls=b[i];
			b[i]=max(b[i]%x,a[i]+(b[i]-a[i])%x);
			if(b[i]==ls)GG();
			else tot+=(ls-b[i])/x;
		}
	}
	cout<<tot<<endl;
}
/*
RGRBGB

*/

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
int a,b,n,w[1001]={0},s,f,x=0;
scanf("%d%d%d",&a,&b,&n);
w[a]++;
w[b]--;
for(int i=0;i<n;i++){
scanf("%d%d",&s,&f);
w[s]++;
if(x<f)x=f;
w[f]--;
}
int k=0;
for(int i=0;i<=x;i++){
k+=w[i];
if(k>1){
printf("1\n");
break;
}
if(i==x)printf("0\n");
}
return 0;
}



Measured memory_bytes: 2692
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(int*)b - *(int*)a; // 大きい順
}

int main(void){
  int n;
  int h[101] = {0};
  int sum;

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

  sum = h[0];
  for(int i = 1; i < n; i++){
    if(h[i] > h[i - 1]){
      sum += h[i] - h[i - 1];
    }
  }
  
  printf("%d\n", sum);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

int bkt[100010]={0};
int A[100010];
int ans;

int solve(int x,int count){
  bkt[x]++;
  if(A[x] == 2)  return count;
  if(bkt[x]>=2)  return -1; 
  count++;
  solve(A[x],count);
  }

int main() {
  int N; cin >> N;
   for(int i=1;i<=N;i++) cin >> A[i];
  cout << solve(1,1) << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include <string.h>
int main(void)
{
  long long int n,c1=0,c2=0,c3=0,c4=0,i;
  char t[4][5]={"AC","WA","TLE","RE"};
  char s[100000][10];
  
  scanf("%lld",&n);
 
  for(i=0;i<n;i++){
    scanf("%s", s[i]);
    
    if(strcmp(s[i],t[0]) == 0)
      c1++;
    if(strcmp(s[i],t[1]) == 0)
      c2++;
    if(strcmp(s[i],t[2]) == 0)
      c3++;
    if(strcmp(s[i],t[3]) == 0)
      c4++;
  }
  
  printf("AC x %lld\nWA x %lld\nTLE x %lld\nRE x %lld\n",c1,c2,c3,c4);
  
  return 0;
  
}


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

using namespace std;

typedef long long ll;

const int N = 100100;

int a[N];
int Next1[N];
int Next2[N];
int Last1[N];
int Last2[N];
vector <int> iNext[N];
vector <int> iLast[N];

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

    for(int i = 1; i <= n; i++) scanf("%d", a + i);

    a[0] = a[n + 1] = n + 1;

    vector <int> stk;

    /// Last1
    stk.push_back(0);
    for(int i = 1; i <= n; i++)
    {
        while(!stk.empty() && a[stk.back()] < a[i])
            stk.pop_back();
        Last1[i] = stk.back();
        iLast[stk.back()].push_back(i);
        stk.push_back(i);
    }
    stk.clear();

    /// Last2
    for(int j : iLast[0])   Last2[j] = 0;

    stk.push_back(0);
    for(int i = 1; i <= n; i++)
    {
        for(int j : iLast[i])
        {
            int I = 0;

            for(int k = 20; ~k; --k)
                if(I + (1 << k) <= stk.size() && a[stk.end()[-(I + (1 << k))]] < a[j])
                    I += (1 << k);

            Last2[j] = stk.end()[- ++I];
        }

        while(!stk.empty() && a[stk.back()] < a[i])
            stk.pop_back();
        stk.push_back(i);
    }
    stk.clear();

    /// Next1
    stk.push_back(n + 1);
    for(int i = n; i >= 1; i--)
    {
        while(!stk.empty() && a[stk.back()] < a[i])
            stk.pop_back();
        Next1[i] = stk.back();
        iNext[stk.back()].push_back(i);
        stk.push_back(i);
    }
    stk.clear();

    /// Next2
    for(int j : iNext[n + 1])   Next2[j] = n + 1;

    stk.push_back(n + 1);
    for(int i = n; i >= 1; i--)
    {
        for(int j : iNext[i])
        {
            int I = 0;

            for(int k = 20; ~k; --k)
                if(I + (1 << k) <= stk.size() && a[stk.end()[-(I + (1 << k))]] < a[j])
                    I += (1 << k);

            Next2[j] = stk.end()[- ++I];
        }

        while(!stk.empty() && a[stk.back()] < a[i])
            stk.pop_back();
        stk.push_back(i);
    }
    stk.clear();

    ll Ans = 0;

    for(int i = 1; i <= n; i++)
    {
        ll Ways1 = (ll) (i - Last1[i]) * (Next2[i] - Next1[i]);
        ll Ways2 = (ll) (Next1[i] - i) * (Last1[i] - Last2[i]);

        Ans += (ll) a[i] * (Ways1 + Ways2);
    }

    cout << Ans << endl;
}


Measured memory_bytes: 11128
#include <stdio.h>
#include <bits/stdc++.h>			
 
#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

#define int ll
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int N = (int)1e5 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;
 
ll need[N], waste[N];
ll a[N];
int n;
vector<int> pr;
 
bool is_prime(int x) {
	for(int i = 2; 1ll * i * i <= x; i ++)
		if(x % i == 0)
			return 0;
	return 1;
}
 
map<ll, int> square;
map<ll, vector<int> > ne, wa;
map<ll, int> ane, awa;
set<ll> st;
bool del[N];
 
main() {
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	for(int i = 1; i <= n; i ++) {
		for(ll x = (int)3e3; x >= 1; x --) {
			if(a[i] % (x * x * x) == 0)	{
				waste[i] = a[i] / (x * x * x);
				break;
			}
		}
	}
	for(int x = 2; x <= (int)5e3; x ++) {
		if(is_prime(x)) {
			pr.pb(x);
		}
	}
	for(int x = 2; x <= (int)1e5; x ++) 
	  if(is_prime(x))
			square[1ll * x * x] = x;
	
	for(int i = 1; i <= n; i ++) {
		ll tmp = a[i], tmp_need = 1;
		for(int it = 0; it < sz(pr); it ++) {
			int cnt = 0;
			while(tmp % pr[it] == 0) 
				cnt ++, tmp /= pr[it];
			cnt %= 3;
			if(cnt == 1) tmp_need *= pr[it] * pr[it];
			if(cnt == 2) tmp_need *= pr[it];			
		}
		if(!square.count(tmp))
			tmp_need *= tmp * tmp;
		else 
			tmp_need *= square[tmp];
		
		need[i] = tmp_need;
	}
	for(int i = 1; i <= n; i ++) {
		ne[need[i]].pb(i), wa[waste[i]].pb(i);
		ane[need[i]] ++, awa[waste[i]] ++;
		st.insert(need[i]);
		st.insert(waste[i]);
	}
	int res = 0;
	for(auto x : st) {
		if(x == 1) continue;
		res += max(ane[x], awa[x]);
 
	 	for(auto ind : ne[x])
	  	if(!del[ind])
	  		ane[need[ind]] --, awa[waste[ind]] --, del[ind] = 1;
	 	for(auto ind : wa[x])
	  	if(!del[ind])
	  		ane[need[ind]] --, awa[waste[ind]] --, del[ind] = 1;
	}
	if(sz(ne[1]) || sz(wa[1]))
		res ++;
	cout << res;
	return 0;  
}


Measured memory_bytes: 77184
#include<iostream>
using namespace std;
int main()
{
  string s,out = "Yes";
  cin >> s;
  for(int i = 0;i < s.length();i++){
    if(i % 2 == 0){
      if(s[i] == 'L'){
        out = "No";
        break;
      }
    } else{
      if(s[i] == 'R'){
        out = "No";
        break;
      }
    }
  }
  cout << out <<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
 
int main() {
	int a, b;
	char op;

	cin >> a >> op >> b;

	if (op == '+')
		cout << a + b << endl;

	else
		cout << a - b << endl;

}

Measured memory_bytes: 3576
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli pot[20];
	void solve(){
		lli A,B,C,K,res=0,maxi=0,i;
		cin>>A>>B>>C>>K;
		maxi=max(A,max(B,C));		
		pot[0]=1;
		for(i=1;i<12;i++)pot[i]=pot[i-1]*2;
		res=A+B+C-maxi+(maxi*pot[K]);
		cout<<res;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char ch[10][10];

int main(){
    int h,w;
    cin>>h>>w;
    int total = 0;
    for(int i = 0; i<h; i++)
        for(int j = 0; j<w; j++){
            cin>>ch[i][j];
            if(ch[i][j]=='#')
                total++;
        }
    int i = 0, j = 0;
    bool ans = 1;
    if(ch[0][0]=='#')
        total--;
    while(1){
        if(i==h-1&&j==w-1)
            break;
        if(ans == 0)
            break;
        if( ch[i+1][j]=='#' && ch[i][j+1]=='#')
            ans = 0;
        else if(ch[i+1][j]=='#'){
            i++;
            total--;
            continue;
        }
        else if(ch[i][j+1]=='#'){
            j++;
            total--;
            continue;
        }

        else
            ans = 0;
    }

    if(total!=0)
        ans = 0;
    if(ans==0)
        cout<<"Impossible"<<endl;
    else
        cout<<"Possible"<<endl;

}


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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

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

    int ans = 1;
    V<int> maxPerColor;
    int A;
    cin >> A;
    maxPerColor.push_back(A);
    for (int i = 1; i < N; i++) {
        int A;
        cin >> A;
        auto itr = lower_bound(maxPerColor.begin(), maxPerColor.end(), A);
        int idx = distance(maxPerColor.begin(), itr) - 1;
        if (idx == -1) {
            ans++;
            maxPerColor.insert(maxPerColor.begin(), A);
        } else {
            maxPerColor[idx] = A;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
#include <limits.h>

int main(void) {
    int n, min, i, x, diff, max_diff = INT_MIN;

    scanf("%d", &n);
    scanf("%d", &min);
    for (i = 1; i < n; i++) {
        scanf("%d", &x);
        diff = x - min;
        if (max_diff < diff) max_diff = diff;
        if (x < min) min = x;
    }
    printf("%d\n", max_diff);

    return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll(x);cin >> (x);
#define stin(x) str(x);cin >> (x);
#define vllin(x,n) vll(x)(n);FOR(i,0,n-1){cin >> (x)[i];}
#define vllin2(a,b,n) vll(a)(n);vll(b)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vllin3(a,b,c,n) vll(a)(n);vll(b)(n);vll(c)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >> (x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vpl4in(x,n) vpl4(x)((n),mp(0,0));FOR(i,0,n-1){cin >> x[i].fi >> x[i].se;}
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define rFOR(i,b,a) for(ll i=a;i>=b;i--)
#define SORT(x) sort(x.be,x.en)
#define rSORT(x) sort(x.rbegin(),x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll MOD = 1000000007;

signed main()
{
    llin(n);
    vector<pair<ll,pair<ll,ll>>> a(n);
    FOR(i,0,n-1){
        cin >>a[i].se.fi>>a[i].se.se;
        a[i].fi=a[i].se.fi+a[i].se.se;
    }
    rSORT(a);
    ll t=1;
    ll s=0;
    FOR(i,0,n-1){
        if(t==1){
            s+=a[i].se.fi;
        }else{
            s-=a[i].se.se;
        }
        t*=-1;
    }
    sal(s)
}

Measured memory_bytes: 2560
#include<stdio.h>
int main(void)
{
 int x, y, i;
 for(i=1;i<=3000;i++)
{
 scanf("%d %d",&x, &y);
 if(x==0 && y==0){
 break;
 }
 if(x > y)
 {          
  printf("%d %d\n",y, x);
  }
 else if(x <= y)
 {
    printf("%d %d\n",x, y);
  }
 }
return 0;
}

Measured memory_bytes: 2576
n = int(input())
s = [input() for i in range(n)]

cnt = 0
cntBA = 0
cntA = 0
cntB = 0
for i in s:
    for j in range(len(i) - 1):
        if i[j:j + 2] == "AB":
            cnt += 1
    #print(i)
    if i[0] == "B" and i[-1] == "A":
        cntBA += 1
    elif i[0] == "B":
        cntB += 1
    elif i[-1] == "A":
        #print(123)
        cntA += 1

#print(cnt, cntA, cntB, cntBA)
ans = cnt + max(0, cntBA - 1)
if cntBA > 0:
    ans += min(cntA, 1)
    cntA -= 1
    ans += min(cntB, 1)
    cntB -= 1
ans += max(min(cntA, cntB), 0)


print(ans)

Measured memory_bytes: 46936
#include<stdio.h>
#include<string.h>
 
int main(){
    int cnt,i,size,sym;
    char msg[100];
    scanf("%s",msg);
    size=strlen(msg);
    for(cnt=0,i=0;i<size;i++){
            sym=(size-1)-i;  
            switch(msg[i]){  
                case 'i':
                if(msg[sym]!='i') cnt++;
                msg[sym]='i';
                break;
                case 'w':
                if(msg[sym]!='w') cnt++;
                msg[sym]='w';
                break;
                case '(':
                if(msg[sym]!=')') cnt++;
                msg[sym]=')';
                break;
                case ')':
                if(msg[sym]!='(') cnt++;
                msg[sym]='(';
                break;
                default:
                cnt=0;
                break;
            }
    }
    printf("%d\n",cnt);
    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, 0, N) {
    cin >> X[i];
  }

  vector<int> ord(N);
  iota(All(ord), 0);

  sort(ord.begin(), ord.end(),  [&](int a, int b) {
    if (X[a] == X[b]) return X[a] > X[b];
    return X[a] < X[b];
  });

  sort(All(X));

  vector<int> ans(N);

  rep(i, 0, N) {
    if (i <= N / 2 - 1) {
      ans[ord[i]] = X[N/2];
    } else {
      ans[ord[i]] = X[N/2 - 1];
    }
  }

  rep(i, 0, N) {
    cout << ans[i] << endl;
  }

  return 0;
};


Measured memory_bytes: 4608
import java.util.Scanner;

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

    int A = scanner.nextInt();
    int B = scanner.nextInt();
    if (A >= 13) System.out.println(B);
    else if (A >= 6) System.out.println(B / 2);
    else System.out.println(0);
  }
}


Measured memory_bytes: 22996
#include <iostream>
#include <cstdlib>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>

using namespace std;

char S[10];
char A[4];
//int B;

int main()
{
        scanf("%s\n",S);
        int a = strlen(S);
        
        if (a==2) printf("%s\n",S );
        else {
                A[0]=S[2];
                A[1]=S[1];
                A[2]=S[0];
                printf("%s\n",A);
        }



}


Measured memory_bytes: 256
/*
INP:
4 4
1 3 2 4
120 90 100
110 50 80
250 70 130
OUT: 550
*/
#include <bits/stdc++.h>
using namespace std;
long long n,m,i,l,r,ans,ct[100005],a[100005],b[100005],c[100005],p[100005];
int main(){
	scanf("%lld%lld",&n,&m);
	for (i=1;i<=m;i++) scanf("%lld",&p[i]);
	for (i=1;i<n;i++) scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
	for (i=1;i<m;i++){
		l=p[i];r=p[i+1];
		while (l!=r){
			if (l<r) {ct[l]++;l++;}
			else {ct[l-1]++;l--;}
		}
	}
	for (i=1;i<=n;i++){
		ans+=min(a[i]*ct[i],c[i]+b[i]*ct[i]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 7124
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define FINISH cout<<"No"<<endl;return 0;

bool arr[810][810];
string ma[810];
ll H, W;
ll hi = LLONG_MAX / 2, wi = hi, hx = 0, wx = 0;

int main() {
	ll K, a, b, c;
	cin >> H >> W >> K;
	for (int i = 0;i < H;i++)cin >> ma[i];
	for (int i = 0;i < H;i++) {
		for (int j = 0;j < W;j++) {
			arr[i][j] = 0;
			if (ma[i][j] == 'S') {
				a = i, b = j;
			}
		}
	}
	queue<tuple<ll, ll, ll>> Q;
	Q.push(make_tuple(a, b, K));
	while (!Q.empty()) {
		tie(a, b, c) = Q.front();
		Q.pop();
		if (ma[a][b] == '#') {
			continue;
		}
		if (a == 0 || b == 0 || a == H - 1 || b == W - 1) {
			cout << 1 << endl;
			return 0;
		}
		if (arr[a][b])continue;
		arr[a][b] = 1;
		hi = min(hi, a);
		wi = min(wi, b);
		hx = max(hx, a);
		wx = max(wx, b);
		if (c < 1)continue;
		Q.push(make_tuple(a - 1, b, c - 1));
		Q.push(make_tuple(a + 1, b, c - 1));
		Q.push(make_tuple(a, b - 1, c - 1));
		Q.push(make_tuple(a, b + 1, c - 1));
	}
	hi = min(hi, H - hx - 1);
	wi = min(wi, W - wx - 1);
	c = min(hi, wi);
	cout << (c - 1) / K + 2 << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
multiset<int>R,B;
struct node
{
	int x,y;
	bool operator<(const node &b)const{return x<b.x;}
}p[200010];
int n;
ll solve()
{
	return 1ll*((*--R.end())-(*R.begin()))*((*--B.end())-(*B.begin()));
}
int main(){
	n=gi();
	for(int i=1;i<=n;i++)
	{
		int x=gi(),y=gi();if(x>y)swap(x,y);
		p[i]=(node){x,y};R.insert(x);B.insert(y);
	}
	sort(p+1,p+n+1);
	ll ans=solve();
	for(int i=1;i<=n;i++)
	{
		R.erase(R.find(p[i].x));B.erase(B.find(p[i].y));
		R.insert(p[i].y);B.insert(p[i].x);
		ans=min(ans,solve());
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 20608
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) A[i] = i - A[i];
	A.emplace_back(INF); //番兵
	DMP(A);

	lint ans = 0;
	for (int i = 0; i < N; i++) {

		if (A[i] > A[i + 1] || A[i] < 0) {
			cout << -1 << "\n";
			return 0;
		}
		
		if (A[i] != A[i + 1]) ans += i - A[i];

	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c;
    if((a+b==c)||(a+c==b)||(b+c==a))
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

vector<vector<int>> Edge(100005);

int main() {
    int N;cin >> N;
    for(int i = 0;i<N-1;i++){
        int a,b;cin >> a >> b;a--;b--;
        Edge.at(a).push_back(b);
        Edge.at(b).push_back(a);
    }
    int Snuke = 0,Fennec = 0;
    vector<int> distS(N);
    vector<bool> seen(N,false);
    queue<P> Q;
    Q.push(make_pair(N-1,0));
    while(!Q.empty()){
        P p = Q.front();Q.pop();
        int from = p.first;int dist = p.second;
        seen.at(from) = true;
        distS.at(from) = dist;
        for(int to : Edge.at(from)){
            if(seen.at(to)) continue;
            Q.push(make_pair(to,dist+1));
        }
    }

    vector<int> distF(N);
    for(int i = 0;i<N;i++) seen.at(i) = false;
    Q.push(make_pair(0,0));
    while(!Q.empty()){
        P p = Q.front();Q.pop();
        int from = p.first;int dist = p.second;
        seen.at(from) = true;
        distF.at(from) = dist;
        for(int to : Edge.at(from)){
            if(seen.at(to)) continue;
            Q.push(make_pair(to,dist+1));
        }
    }
    for(int i = 0;i<N;i++){
        if(distS.at(i) < distF.at(i)) Snuke++;
        else Fennec++;
    }
    if(Snuke >= Fennec) cout << "Snuke" << endl;
    else cout << "Fennec" << endl;
}


Measured memory_bytes: 6784
f(int*a,int*b){return*b-*a;}
n,k,a[55],i,j,s;
main(){
	for(scanf("%d%d",&n,&k);~scanf("%d",a+i++););
	for(qsort(a,n,4,f);j<k;)s+=a[j++];
	printf("%d",s);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	int n,a,b;
	scanf("%i %i %i",&n,&a,&b);
	int A=0,B=0,C=0;
	vector<int> p(n);
	for(int &i:p)
	{
		scanf("%i",&i);
		if(i<=a) A++;
		else if(i>a && i<=b) B++;
		else C++;
	}
	printf("%i\n",min(A,min(B,C)));
	return 0;
}

Measured memory_bytes: 256
def koh(N):
    y = N
    p = 1
    c = 0
    while p <= N:
        if y % p == 0:
            c += 1
        p += 1
    if c == 0:
        c = 1
    return c
M = int(input())
output = 0
for i in range(3, M + 1, 2):
    if koh(i) == 8:
        output += 1
print(output)


Measured memory_bytes: 3060
#include <stdio.h>
int main ()
{
	int a,b,z=1,i=0;
	scanf("%i%i",&a,&b);
	if (z>=b)
	{
		printf("0");
		return 0;
	}
	else
	{
		while(z<b)
		{
			z=z+a-1;
			i++;
		}
	}
	printf ("%i",i);
	return 0;
}


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

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

    ll money = 100;
    int year = 0;

    while (money < X) {
        money += money /100;
        year++;
    }

    cout << year << endl;

    return 0;
}



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

int N,M;
int WA[105000];
bool AC[105000];

void solve();

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

void solve(){
    std::cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;

    for(int i = 1; i <= N; i++){
        WA[i] = 0;
        AC[i] = false;
    }

    while(M--){
        int p;
        std::string S;
        std::cin >> p >> S;
        if(AC[p])continue;
        if(S == "AC"){
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        }else if(S == "WA"){
            WA[p]++;
        }
    }
    std::cout << ACnum << " " << WAnum << std::endl;
    return;
}

Measured memory_bytes: 768
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
  
typedef long long ll;
const int N = 100010;
const ll mod = 1e9 + 7;

int a[N], b[N];

int main()
{
    int n, mx = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        ++b[a[i]];
        mx = max(mx, a[i]);
    }
    int p = mx / 2;
    if ((mx & 1) == 0) --b[p];
    for (int i = p + 1; i <= mx; ++i) {
        --b[i], --b[i];
        if (b[i] < 0) {
            puts("Impossible");
            return 0;
        }
    }
    for (int i = 0; i <= p + (mx & 1); ++i) {
        if (b[i]) {
            puts("Impossible");
            return 0;
        }
    }
    puts("Possible");
    return 0;
}

Measured memory_bytes: 256
N = int(input())
str_list = [input() for i in range(N)]

_a_cnt = 0
b__cnt = 0
b_a_cnt = 0
other_cnt = 0

ans = 0
for s in str_list:
    if s[0] == "B" and s[-1] == "A":
        b_a_cnt += 1
    elif s[-1] == "A":
        _a_cnt += 1
    elif s[0] == "B":
        b__cnt += 1
    else:
        other_cnt += 1
    ans += s.count("AB")

if _a_cnt > 0 and b__cnt > 0:
    ans += b_a_cnt + 1 + min(_a_cnt - 1, b__cnt - 1)
elif _a_cnt > 0 or b__cnt > 0:
    ans += b_a_cnt
elif b_a_cnt >= 2:
    ans += b_a_cnt - 1

print(ans)


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

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


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

int main(){
	ll N;
	cin >> N;
	vector<ll> h(N+7),dp(N+7,INF);

	for(int i=1;i<=N;i++){
		cin >> h[i];
	}

	dp[1] = 0;
	for(int i=1;i<=N;i++){
		dp[i+1] = min( dp[i+1] , dp[i]+abs(h[i]-h[i+1]) );
		dp[i+2] = min( dp[i+2] , dp[i]+abs(h[i]-h[i+2]) );
	}

	cout << dp[N] << endl;
}

Measured memory_bytes: 1792