akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
#define SIZE 1005
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, k, c;

int main() {
	io(); cin >> n >> k >> c;
	string s; cin >> s;
	int pos = -1, res = 0;
	set<int> st, st2;
	rep(i, 0, (s.length() - 1)) {
		if (pos >= i) continue;
		if (s[i] == 'x') continue;
		if (st.size() == k) {
			++res;
			break;
		}
		pos = i + c;
		st.insert(i);
	}
	if (res) return 0;
	pos = s.length();
	for (int i = s.length() - 1; i >= 0; --i) {
		if (s[i] == 'x') continue;
		if (pos <= i) continue;
		if (st2.size() == k) {
			++res;
			break;
		}
		pos = i - c;
		if (st.count(i)) st2.insert(i);
	}
	if (res) return 0;
	for (auto i : st2) cout << i + 1 << '\n';
}

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


int main()	
{
	int n;
	char a;
	string s;
	map<string,int>m;
	bool flag=true;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(i)
		{
			if(s[0]!=a)flag=false;
			if(m[s]==1)flag=false;
		}
		m[s]++;
		a=s[s.length()-1];
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
//#include <boost/multiprecision/cpp_int.hpp>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll  unsigned long long
#define fp cout<<fixed<<setprecision(9);
#define ifor(j,n) for(int i=j ;i<n;i++)
#define jfor(k,n) for(ll j=k ;j<n;j++)
#define pb push_back
#define mod 1000000007
using namespace std;
//using namespace boost::multiprecision;

//Compiler version g++ 6.3.0
int search (vector <long long> v,long long m,int n) 
{ 

    int start = 0;
    int ans = -1; 
    while (start <=n) 
    { 
     int mid = (start + n) / 2;
     if (v[mid] <= m) 
         start = mid + 1;
     else
   { 
   ans = mid; 
   n = mid - 1; 

       } 

    } 
    return ans; 
} 

int main()
{
 FAST 
   string s,t;
  cin>>s>>t;
  int ans=INT_MAX,temp;
  for(int i=0;i<=s.size()-t.size();i++)
  {
    temp=0;
    for(int j=0;j<t.size();j++)
    {
      if(s[i+j]!=t[j])
        	temp++;
    }
    ans=min(ans,temp);
  }
  cout<<ans;
}


Measured memory_bytes: 3680
n=int(input())
l=[]
m=[]
for i in range(0,n):
  a,b=map(int,input().split())
  l.append(a)
  m.append(b)
c=0
i=0
while i<=n-3:
  if l[i]==m[i] and l[i+1]==m[i+1] and l[i+2]==m[i+2]:
      c=3
  i=i+1
if c==3:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 9096
#include <stdio.h>
typedef long long Int;
Int sign(Int a, Int b) {
    return a < b ? 1 : a > b ? -1 : 0;
}
int main() {
    Int n;
    scanf("%lld", &n);
    if (n == 1) {
        puts("1");
        return 0;
    }
    Int prev_num;
    Int prev_sign = 0;
    Int ans = 1;
    for (Int i = 0; i < n; i++) {
        Int a;
        scanf("%lld", &a);
        if (i > 0) {
            Int current_sign = sign(prev_num, a);
            if (i == 1) {
                prev_sign = current_sign;
            } else if (current_sign != 0) {
                if (current_sign != prev_sign) {
                    if (prev_sign != 0) {
                        ans++;
                        prev_sign = 0;
                    } else {
                        prev_sign = current_sign;
                    }
                }
            }
        }
        prev_num = a;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 6228
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)

int main() {
    int n; cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    ll dp[n][2];
    dp[0][0] = a[0];
    dp[0][1] = -a[0];
    rrep(i, 1, n - 1) {
        dp[i][0] = max(dp[i - 1][0] + a[i], dp[i - 1][1] - a[i]);
        //前そのまま + 自分反転、
        dp[i][1] = max(dp[i - 1][0] - a[i], dp[i - 1][1] + a[i]);
    }
    //rep(i, n - 1) {rep(j, 2) cout << setw(11) << left << dp[i][j] << " "; cout << endl;}
    //最後i + 1番目選べないからそのまま
    cout << max(dp[n - 2][0] + a[n - 1], dp[n - 2][1] - a[n - 1]) << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
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; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int N = inputVal<int>();
	vector<int> d = inputVec<int>(N);
	sort(d.begin(), d.end());

	const int nb = d[N / 2] - d[N / 2 - 1];

	outputVal(nb);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<numeric>
#include<cmath>

using namespace std;

int main()
{
	int n; cin >> n;
	int num = n / 1000 + 1;
	int ans = num * 1000 - n;
	if (ans == 1000)
	{
		cout << 0;
	}
	else
	{
		cout << ans;
	}


	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	int a[n];
	zip(i, 0, n) cin >> a[i];
	sort(a, a + n);
	vii v;
	zip(i, 1, n - 1)
	{
		if (a[i] > 0)
		{
			v.pb({a[0], a[i]});
			a[0] = a[0] - a[i];

		}
		else if (a[i] <= 0)
		{
			v.pb({a[n - 1], a[i]});
			a[n - 1] = a[n - 1] - a[i];

		}
	}
	v.pb({a[n - 1], a[0]});
	cout << a[n - 1] - a[0] << en;
	zip(i, 0, v.size())
	{
		cout << v[i].ff << " " << v[i].ss << en;
	}

	// multiset<int>sp, sn;
	// zip(i, 0, n)
	// {
	// 	cin >> a[i];
	// 	if (a[i] > 0)
	// 	{
	// 		sp.insert(a[i]);
	// 	}
	// 	else
	// 	{
	// 		sn.insert(a[i]);
	// 	}
	// }
	// if(sn.size()==0)
	// {
	// 	int ans=0;
	// 		while (sp.size() > 1)
	// 	{
	// 		auto it1 = sp.begin();
	// 		auto it2 = ++it1;
	// 		int p = *it2 - *it1;
	// 		sp.erase(it1);
	// 		sp.erase(it2);

	// 		sp.insert(p);
	// 		if (sp.size() <= 2)
	// 		{
	// 			break;
	// 		}
	// 		v.pb({*it2, *it1});
	// 	}
	// 	auto it1 = sp.begin();
	// 	auto it2 = ++it1;
	// 	int p = *it2 - *it1;
	// 	sp.erase(it1);
	// 	sp.erase(it2);
	// 	v.pb({*it2, *it1});
	// 	ans=*it2-*it1;
	// 	cout<<ans<<en;
	// 	zip(i,0,v.size())
	// 	{
	// 		cout<<v[i].ff<<" "<<v[i].ss<<en;
	// 	}
	// }

	// vii v;
	// int ans = 0;

	// int x = p;
	// for (int i : sn)
	// {
	// 	v.pb({x, i});
	// 	ans += (x - i);
	// }
	// cout << ans << en;
	// zip(i, 0, v.size())
	// {
	// 	cout << v[i].ff << " " << v[i].ss << en;
	// }

	//s.insert(p);






	return 0;
}



Measured memory_bytes: 6108
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector< pair<ll, ll> > p(n);
	for(int i = 0; i < n; ++i) {	
		ll a, b;
		cin >> a >> b;
		
		p[i] = make_pair(b, a);
	}
	
	sort(p.begin(), p.end());
	
	bool yes = true;
	ll t = 0;
	
	for(auto& x : p) {
		t += x.second;
		if( t > x.first ) {
			yes = false;
			break;
		}			
	}
	
	if( yes ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<int>A(n);
  for(int i=0;i<n;i++) cin >> A[i];
  cout<< (n-1+k-1-1)/(k-1) <<endl;
}


Measured memory_bytes: 640
N = int(input())
a = list(map(int, input().split()))

increase = False
decrease = False
ans = 1
for i in range(N-1):
    dif = a[i+1]-a[i]
    if dif>0:
        if not decrease:
            increase = True
        else:
            ans += 1
            increase, decrease = False, False
    if dif<0:
        if not increase:
            decrease = True
        else:
            ans += 1
            increase, decrease = False, False
print(ans)

Measured memory_bytes: 14224
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
using namespace std;
const int N=200500; 
char a[N];
int main() 
{
	stack<char> b;
	scanf("%s",&a);
	int size=strlen(a);
	char ch;
	b.push(a[0]);
	for(int i=1;i<size;i++)
	{
		if(!b.empty())
		{
			ch=b.top();
			if(ch=='S'&&a[i]=='T') 
				b.pop();
			else 
				b.push(a[i]); 
		}
		else b.push(a[i]);	
	}
	int size1=b.size();
	printf("%d\n",size1);
	return 0;
 } 

Measured memory_bytes: 640
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;

		b>>=1;
	}
	return res;
}

int main(){
	IOS;
	int a,b;
	cin>>a>>b;
	if(a>=13) cout<<b;
	else if(a<=5) cout<<0;
	else cout<<b/2;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

vector<int> E[(1 << 17)];

bool used[(1 << 17)] = {};

int main(){
	
	int N, M, K;
	cin >> N >> M >> K;
	
	bool D[200] = {};
	map<int, int> m;
	
	for(int i = 0; i < M; i++){
		int num;
		cin >> num;
		D[num] = true;
		m[num] = i;
	}
	
	int v[200][200];
	for(int i = 0; i < N; i++){
		for(int j = 0; j < K; j++){
			cin >> v[i][j];
		}
	}
	
	for(int i = 0; i < K; i++){
		int to[100] = {};
		for(int j = 1; j <= N; j++){
			if(D[j] && !D[v[j - 1][i]]){
				to[m[j]] = -1;
			}else if(D[j]){
				to[m[j]] = m[v[j - 1][i]];
			}
		}
		/*
		for(int j = 0; j < M; j++){
			cout << to[j] << endl;
		}
		*/
		for(int j = 0; j < (1 << M); j++){
			int t = 0;
			for(int k = 0; k < M; k++){
				if(j & (1 << k) && to[k] != -1){
					t |= (1 << to[k]);
				}
			}
			E[j].push_back(t);
			//cout << j << " " << t << endl;
		}
	}
	
	queue<int> que;
	int ans;
	
	que.push((1 << M) - 1);
	for(int loop = 0; !que.empty(); loop++){
		int sz = que.size();
		for(int i = 0; i < sz; i++){
			int hoge = que.front();
			que.pop();
			if(used[hoge]){
				continue;
			}
			used[hoge] = true;
			if(hoge == 0){
				ans = loop;
			}
			for(int k = 0; k < E[hoge].size(); k++){
				que.push(E[hoge][k]);
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 54788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n, k, d[100005], INF = 1e9;
vector<int> g[100005];
bool a[100005], b[100005], c[100005];

void dfs(int x, int cnt) {
	c[x] = true;
	d[x] = min(d[x], cnt);
	if (cnt+1 < k) {
		FOR(i, g[x].size()) {
			if (d[g[x][i]] > cnt+1) dfs(g[x][i], cnt+1);
		}
	}
	return;
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
	FOR(i, n) {
		int x;
		cin >> x;
		if (x == 0) a[i] = true;
		else {
			b[x-1] = true;
			g[i].push_back(x-1);
		}
	}
	fill(d, d+n, INF);
	FOR(i, n) {
		if (!b[i] && !a[i]) dfs(i, 0);
	}
	int ret = 0;
	FOR(i, n) {
		if (a[i] || c[i]) ret++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 12388
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

ll _rand() {
	static random_device rd;
	static mt19937 mt(rd());
	string ret="";
	ret+=to_string(mt());
	ret+=to_string(mt());
	return stol(ret.substr(0,18));
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin>>N;
	vector<ll> a(N);
	REP(i,N) cin>>a[i];
	map<ll,__int128> hash;
	REP(i,N) hash[a[i]]=-1;
	REP(i,N) if(hash[a[i]]==-1) hash[a[i]]=_rand();
	__int128 h1=1,h2=1;
	vector<ll> ans;
	REP(i,N) {
		h1*=hash[a[i]];
		h2*=hash[a[N-1-i]];
		h1%=MOD; h2%=MOD;
		if(h1==h2) ans.pb(i+1);
	}
	if((ll)ans.size()==0) cout<<endl;
	DUMP(ans);
}



Measured memory_bytes: 7600
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = (a); i <(b); i++)
#define forn(i,a,b) for (int i = (a); i >(b); i--)
#define mod 1000000007
#define multiple_testcases_t int t;cin>>t;while(t--){solve();}
#define single_testcase_t solve();
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

// <----- Actual solve() function to print output -----> //
int tc=1;
void solve()
{
   ll n,m,k=0,z=-1,ans=0;
   cin>>n;
   ll a[n];
   vector<ll> v(1e6+7,0);
   
   forp(i,0,n)
   {
       cin>>a[i];
       if(i==0)
       k=a[i];
       else
       k=__gcd(k,a[i]); 
       v[a[i]]++;
   }
   
   int flag=1;
   for(int i=2;i<=1e6;i++)
   {
       ll f=0;
           for(int j=i;j<=(1e6);j+=i)
           {
               if(v[j]>0)
               {
                   f+=v[j];
               }
               if(f>=2)
               {
                   flag=0;
                   break;
               }
           }
       if(flag==0)
       break;
   }
   
   if(flag==1)
   {
       cout<<"pairwise coprime";
   }
   else if(k==1)
   {
       cout<<"setwise coprime";
   }
   else
   cout<<"not coprime";

 //  cout<<"\n";      //if t>1 uncomment this
}

// MAIN function --------------------------------------------------------------------------//
int main()
{
    fast_io
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

  single_testcase_t
 // multiple_testcases_t
return 0;
}





Measured memory_bytes: 18764
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Numerics;

namespace competitive
{
    class Program
    {
        static void Main(string[] args)
        {
            var scanner = new Scanner();
            var s = scanner.Next();
            var aind = s.IndexOf('A');
            var lind = s.LastIndexOf('Z');
            Console.WriteLine(lind - aind + 1);
        }
    }

    public static class Extensions
    {
        public static int ToInt(this string str) => int.Parse(str);
        public static double ToDouble(this string str) => double.Parse(str);
        public static long ToLong(this string str) => long.Parse(str);
        public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    }

    public class Scanner
    {
        private TextReader reader;
        public Scanner()
        {
            reader = Console.In;
        }
        public Scanner(TextReader reader)
        {
            this.reader = reader;
        }
        private string NextWord()
        {
            var sb = new StringBuilder();
            while (true)
            {
                var c = reader.Read();
                if (c == -1 || c == 13 || c == 10)
                {
                    break;
                }
                sb.Append((char)c);
            }
            return sb.ToString();
        }
        public int NextInt()
        {
            return NextWord().ToInt();
        }
        public string Next()
        {
            return NextWord();
        }
        public double NextDouble()
        {
            return NextWord().ToDouble();
        }
        public long NextLong()
        {
            return NextWord().ToLong();
        }
        public BigInteger NextBigInteger()
        {
            return NextWord().ToBigInteger();
        }
        public string NextLine()
        {
            return reader.ReadLine();
        }
    }
}


Measured memory_bytes: 11616
from collections import deque

H,W=map(int,input().split())
S=[input() for i in range(H)]

CHECK=[[0]*W for i in range(H)]
ANSLIST=[]

for i in range(H):
    for j in range(W):
        if CHECK[i][j]==1:
            continue
        QUE = deque()
        QUE.append((i,j))
        BC=0
        WC=0

        while QUE:
            x,y=QUE.pop()
            if CHECK[x][y]==1:
                continue

            
            CHECK[x][y]=1
            #print(x,y,QUE,CHECK)

            if S[x][y]=="#":
                BC+=1
            else:
                WC+=1


            for k,l in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
                #print("!",k,l,x,y)
                if k<0 or l<0 or k>=H or l>=W:
                    #print("?",k,l)
                    continue
                if CHECK[k][l]==1:
                    continue

                if S[k][l]!=S[x][y]:
                    QUE.appendleft((k,l))
                    #print(x,y)

        ANSLIST.append((BC,WC))
        #print(i,j,ANSLIST,CHECK)

ANS=0
for a,b in ANSLIST:
    ANS+=a*b

print(ANS)




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

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    vector<int> r(N);
    for (int i = 0; i < N; ++i) r[0] += A[i] * (i % 2 == 0 ? 1 : -1);
    for (int i = 1; i < N; ++i) r[i] = 2 * A[i-1] - r[i-1];
    
    for (int i = 0; i < N; ++i) {
        cout << r[i] << (i == N - 1 ? '\n' : ' ');
    }
}

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

typedef long long int llint;

int n;
int i, j;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

struct P
{
  int n, t;
  P(){}
  P(int n, int t) : n(n), t(t) {}

  bool operator < (const P &a) const {
    if(n != a.n) return n < a.n;
    else         return t > a.t;
  }
};

int main()
{
  cin>> n;

  vector<P> v;

  int m;
  for(i = 0; i < n; i++) {cin>> m; v.push_back(P(m, 1));}
  for(i = 0; i < n; i++) {cin>> m; v.push_back(P(m, 2));}
  for(i = 0; i < n; i++) {cin>> m; v.push_back(P(m, 3));}

  sort(v.begin(), v.end());

  llint cnt = 0;
  llint a = 0, c = n;

  for(i = 0; i < n * 3; i++) {
    if(v[i].t == 2) {
      cnt += a * c;
    } else if(v[i].t == 1) {
      a++;
    } else {
      c--;
    }
    
  }

  cout<< cnt <<endl;
    
  return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	ll n;
	std::cin >> n;
	std::vector<ll> v(n+1);
	ll full = 0;
	v[0] = 0;
	for (size_t i = 1; i < n+1; i++) {
		std::cin >> v[i];
		full += abs(v[i]-v[i-1]);
	}
	v.push_back(0);
	full += abs(v[n]);
	for (size_t i = 1; i < n+1; i++) {
		std::cout << full - abs(v[i]-v[i-1]) - abs(v[i+1]-v[i]) + abs(v[i+1] - v[i-1]) << '\n';
	}
	return 0;
}


Measured memory_bytes: 2032
////#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int a, b;
	cin >> a >> b;
	if (b < a) {
		cout << a - 1<< endl;
	} else {
		cout << a << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  int w[n], e[n], c=n;
  for (int i=0, c=0; i<n; i++)
    w[i] = (i>0)? (w[i-1]+(s[i-1]=='W'? 1: 0)): 0;
  for (int i=n-1; i>=0; i--)
    e[i] = (i<n-1)? (e[i+1]+(s[i+1]=='E'? 1: 0)): 0;
  for (int i=0; i<n; i++)
    c = min(c, w[i]+e[i]);
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 3076
def solve():
    ans = 0
    for i in range(n):
        ans += check(i)
    print(ans)
    return

def check(i):
    for adj in r[i]:
        if h[adj] >= h[i]:
            return 0
    return 1




n, m = [int(s) for s in input().split(" ")]
h = [int(s) for s in input().split(" ")]
r = [[] for i in range(n)]
for i in range(m):
    a, b = ([int(s) for s in input().split(" ")])
    r[a-1].append(b-1)
    r[b-1].append(a-1)
solve()


Measured memory_bytes: 91872
import sys


class Node:
    def __init__(self):
        self.parent = self.left = self.right = None
        self.height = self.depth = None


n = int(sys.stdin.readline())

nodes = [Node() for _ in range(n)]

for _ in range(n):
    id, left, right = map(int, sys.stdin.readline().split())
    if left != -1:
        nodes[id].left = left
        nodes[left].parent = id
    if right != -1:
        nodes[id].right = right
        nodes[right].parent = id


def set_height(id):
    node = nodes[id]
    height = max(
        -1 if child is None else set_height(child)
        for child in (node.left, node.right)
    ) + 1
    node.height = height
    return height


def set_depth(id, depth):
    node = nodes[id]
    node.depth = depth
    for child in (node.left, node.right):
        if child is not None:
            set_depth(child, depth + 1)


root_id = next(i for i, node in enumerate(nodes) if node.parent is None)
set_height(root_id)
set_depth(root_id, 0)

for id, node in enumerate(nodes):
    sibling = -1
    if node.parent is not None:
        parent = nodes[node.parent]
        sibling = parent.right if parent.left == id else parent.left
        if sibling is None:
            sibling = -1

    node_type = 'internal node'
    if node.parent is None:
        node_type = 'root'
    elif node.left is None and node.right is None:
        node_type = 'leaf'

    print(
        (
            'node %d: parent = %d, sibling = %d, ' +
            'degree = %d, depth = %d, height = %d, %s'
        ) % (
            id,
            -1 if node.parent is None else node.parent,
            sibling,
            sum(child is not None for child in (node.left, node.right)),
            node.depth,
            node.height,
            node_type
        ))



Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(int i=int(x);i<int(y);++i)
#define For(i,x,y)  for(int i=int(x);i<=int(y);++i)
#define FOr(i,x,y)  for(int i=int(x);i>=int(y);--i)
#define pi acos(-1) 
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define Max(x,y)    ((x)=((x)<(y)?(y):(x)))
#define Min(x,y)    ((x)=((x)>(y)?(y):(x)))
#define E(x)        return writeln(x),0
#define LL			(long long)
#define p(x)        printf("~%lld~\n",LL(x))
#define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_; 
#endif 
#define NEG 1
    static const int GYN=2333333;
    char SZB[GYN],*SS=SZB,*TT=SZB;
    inline char gc(){   if (SS==TT){  TT=(SS=SZB)+fread(SZB,1,GYN,stdin); if (SS==TT) return '\n';  }   return *SS++;    }
#if NEG
    inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);}
	void writeln(ll x){write(x);puts("");}
}using namespace SHENZHEBEI;
vector<ll>g[1010];
ll a[1010],h[1010],n;
bitset<5010>f;
void dfs(ll x){
	rep(i,0,g[x].size())dfs(g[x][i]);
	ll sum=0;f.reset();f[0]=1;
	rep(i,0,g[x].size()){
		f=(f<<a[g[x][i]])|(f<<h[g[x][i]]);
		sum+=a[g[x][i]]+h[g[x][i]];
	}
	FOr(i,a[x],0)if (f[i]){
		h[x]=sum-i;
		return;
	}puts("IMPOSSIBLE");exit(0);
}
int main(){
//	freopen("cf.in","r",stdin);
//	freopen("work.out","w",stdout);
	n=read();
	For(i,2,n)g[read()].push_back(i);
	For(i,1,n)a[i]=read();
	dfs(1);
	puts("POSSIBLE");
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ll n=0;
    cin>>n;
    ll sum=100;
    ll c=0;
    while(sum<n){
      ll i=sum/100;
      sum+=i;
      ++c;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3652
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include<regex>
#include <unordered_map>  

using namespace std;

//conversion
//------------------------------------------
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	map<int, int> m;

	vector<int> a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		m[a[i]]++;
	}

	sort(a.begin(), a.end(), greater<int>());

	LL l1 = 0;
	LL l2 = 0;

	for (int i = 0; i < n; i++) {
		if (m[a[i]] >= 2) {
			l1 = a[i];
			m[a[i]] -= 2;
			break;
		}
	}

	for (int i = 0; i < n; i++) {
		if (m[a[i]] >= 2) {
			l2 = a[i];
			m[a[i]] -= 2;
			break;
		}
	}

	LL ans = l1*l2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5376
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
d=[0]*(N+1)
j=0
for i in range(A[0],N+A[0]):
  try:
    if i==A[j]:
      d[i]+=1
      j+=1
  except:
    pass
#print(d)
print(min(sum(d[:X]),sum(d[X:])))

Measured memory_bytes: 9072
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

spare_win = now_win = spare = win = 0
ans = 0
for i in range(N):
    spare_win = 0
    if spare:
        spare_win = min(A[i], spare)
        spare = 0
    now_win = min( (A[i] - spare_win), B[i])
    spare = B[i] - now_win
    ans += (now_win + spare_win)
ans += min(A[N], spare)
print(ans)


Measured memory_bytes: 73444
/*
https://atcoder.jp/contests/dp/tasks/dp_a
*/

#include <iostream>

using namespace std;

int dp[100000];

int h_diff(int*arr, int N,int k){
	if( N == 0 ) {
		dp[0]=0;
		return dp[N];
	}

	if( N > 0 && N <= k )  {
		dp[N] = abs(arr[N]-arr[0]);
		return dp[N];
	}

	for(int i = 1;i <= k;i++){
		if(dp[N-i] == -1)
			dp[N-i] = h_diff(arr,N-i,k);
	}
	
	dp[N] = abs(arr[N] - arr[N-1]) + dp[N-1];
	for(int i = 2;i <= k;i++){
		int m = abs(arr[N] - arr[N-i]) + dp[N-i];
		if(m < dp[N])
			dp[N] = m;
	}
	
	return dp[N];

}


int main(){

	int N,k;
	cin >> N >> k;
	int arr[N];

	for(int i=0;i<N;i++){
		cin >> arr[i];
		dp[i] = -1;
	}

	
	cout << h_diff(arr,N-1,k)<< endl;


	return 0;
}

Measured memory_bytes: 13640
#include <stdio.h>
#include <ctype.h>

int main(void)
{
	char a[11], b[11], c[11];
	char A, B, C;
	
	scanf("%s %s %s", a, b, c);
	A = toupper(a[0]);
	B = toupper(b[0]);
	C = toupper(c[0]);
	
	printf("%c%c%c", A, B, C);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>

using namespace std;

int ans1,ans2;

int main()
{
	string s;
	cin>>s;
	
	for (int i=0;i<=2;++i)
		if (s[i]=='A')
			ans1++;
		else
			ans2++;
			
	if (ans1==0 || ans2==0){
		cout<<"No"<<endl;
		return 0;
	}
	
	cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main 
{ 

	 static FastReader sc=new FastReader(); 
	  public static void main(String[] args) 
    {
    int n=i();
    int A[]=new int[n];
    input(A);
    int c=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            //long s=A[i]+A[j];
            for(int k=j+1;k<n;k++){
                if(A[i]!=A[j]&&A[j]!=A[k]&&A[i]!=A[k])
                if(c(A[i],A[j],A[k])==1)
                c++;
            }
        }
    }
    
        System.out.println(c);
        	
        	
			
	
	} 
	 public static int c(long a, 
                                long b, long c) 
    { 
        // check condition 
        if (a + b <= c || a + c <= b || b + c <= a) 
            return 0; 
        else
            return 1; 
    } 
    	
   static void input(int A[]) {
	   for(int i=0;i<A.length;i++) {
		   A[i]=sc.nextInt();
	   }
   }
     static int i() {
    	 return sc.nextInt();
     }
     static String s() {
    	 return sc.next();
     }
     static long l() {
    	 return sc.nextLong();
     }
     public static String rev(String str){  
    	    char ch[]=str.toCharArray();  
    	    String rev="";  
    	    for(int i=ch.length-1;i>=0;i--){  
    	        rev+=ch[i];  
    	    }  
    	    return rev;  
    	}  
        static void shuffleArray(int[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }   
}
  
        
        
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
} 





Measured memory_bytes: 33272
def solve(n, m, PS):
    d = {}
    scores = [0, 0]
    for p, s in PS:
        if p not in d:
            d[p] = {'wa': 0, 'ac': 0}
        if d[p]['ac'] > 0:
            continue
        if s == 'AC':
            d[p]['ac'] = 1
            scores[0] += 1
            scores[1] += d[p]['wa']
        if s == 'WA':
            d[p]['wa'] += 1
    return scores

_n, _m = map(int, input().split())
_PS = [input().split() for _ in range(_m)]
_scores = solve(_n, _m, _PS)
print(_scores[0], _scores[1])


Measured memory_bytes: 68048
using System;

namespace ABC049
{
    class C
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            //入力された文字列を反転させる
            string rs = Reverse(s);

            //指定があった4つの文字列を反転させて配列化する
            string[] input = { "dream", "erase", "eraser", "dreamer" };
            for (int i = 0; i < 4; i++)
            {
                input[i] = Reverse(input[i]);
            }

            //前から4つの中のどれかが対応しているか確認する
            int count = 0;
            for (int i = 0; i < rs.Length;)
            {
                count = i;
                for (int j = 0; j < 4; j++)
                {
                    if ((i + input.Length) > rs.Length) { }
                    if (rs.Substring(i, input[j].Length) == input[j])
                    {
                        i += input[j].Length;
                        break;
                    }
                }

                if (i == count)
                {
                    Console.WriteLine("NO");
                    return;
                }

            }
            Console.WriteLine("YES");
            return;
        }

        static string Reverse(string s)
        {
            Char[] c = s.ToCharArray();
            Array.Reverse(c);
            string rs = new string(c);
            return rs;
        }
    }
}


Measured memory_bytes: 13108
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        h: i64,
        n: usize,
        a: [i64; n],
    }

    let sum: i64 = a.iter().sum();

    let ans = if sum >= h { "Yes" } else { "No" };

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


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int INF = 1e9 + 7;

int n;
ll lm[2];
int can[maxn][2];
ll a[maxn];

class SegmentTree{
private:
	static const int siz = 131072;
public:
	int dat[siz << 1], tag[siz << 1];
	
	inline int size(){ return siz; }
	
	inline void pushDown(int x){
		if(tag[x]){
			tag[x << 1] = tag[x << 1 | 1] = 1;
			dat[x << 1] = dat[x << 1 | 1] = 0;
			tag[x] = 0;
		}
		return;
	}
	
	inline void update(int x, int l, int r, int y, int k){
		if(l == r){
			(dat[x] += k) %= INF;
			return;
		}
		int md = l + r >> 1;
		pushDown(x);
		if(y <= md)
			update(x << 1, l, md, y, k);
		else
			update(x << 1 | 1, md + 1, r, y, k);
		dat[x] = (dat[x << 1] + dat[x << 1 | 1]) % INF;
		return; 
	}
	
	inline void modify(int x, int l, int r, int s, int t){
		if(s > t)
			return;
		if(l >= s && r <= t){
			dat[x] = 0;
			tag[x] = 1;
			return;
		}
		int md = l + r >> 1;
		pushDown(x);
		if(s <= md)
			modify(x << 1, l, md, s, t);
		if(t > md)
			modify(x << 1 | 1, md + 1, r, s, t);
		dat[x] = (dat[x << 1] + dat[x << 1 | 1]) % INF;
		return;
	}
	
	inline int query(int x, int l, int r, int s, int t){
		if(s > t)
			return 0;
		if(l >= s && r <= t)
			return dat[x];
		int md = l + r >> 1;
		pushDown(x);
		if(s > md)
			return query(x << 1 | 1, md + 1, r, s, t);
		if(t <= md)
			return query(x << 1, l, md, s, t);
		return (query(x << 1, l, md, s, t) + query(x << 1 | 1, md + 1, r, s, t)) % INF;
	}
}seg[2];

int main(){
	scanf("%d%lld%lld", &n, &lm[0], &lm[1]);
	FOR(i, 0, n){
		scanf("%lld", a + i);
		FOR(t, 0, 2)
			can[i][t] = (i ? can[i - 1][t] : true) & (i ? (a[i] - a[i - 1] >= lm[t]) : true);
	}
	
	FOR(i, 1, n){
		FOR(t, 0, 2) if(can[i - 1][t ^ 1]){
			seg[t].update(1, 0, seg[t].size() - 1, i - 1, 1);
		}
		if(i == n - 1)
			break;
		int res[2];
		FOR(t, 0, 2){
			int pos = lower_bound(a, a + n, a[i + 1] - lm[t ^ 1] + 1) - a - 1;
			res[t] = seg[t].query(1, 0, seg[t].size() - 1, 0, pos);
		}
		FOR(t, 0, 2) if(a[i + 1] - a[i] < lm[t])
			seg[t].modify(1, 0, seg[t].size() - 1, 0, i);
		FOR(t, 0, 2)
			seg[t ^ 1].update(1, 0, seg[t ^ 1].size() - 1, i, res[t]);
	}
	
	int res = can[n - 1][0] + can[n - 1][1];
	
	printf("%d\n", (seg[0].dat[1] + seg[1].dat[1] + res) % INF);
	return 0;
}


Measured memory_bytes: 8464
n = int(input())
data = {}
for i in range(n):
    S = list(input())
    S.sort()
    a = "".join(S)
    if a in data:
        data[a] += 1
    else:
        data[a] = 1
else:
    ans = 0
    for j in data.values():
        ans += j*(j-1)//2
    else:
        print(ans)
        

Measured memory_bytes: 17808
#include<stdio.h>
int main()
{
	int a,b,c,d,e=0,f,g,h,i,j,k;
	for(d=1;d<=100;d++)
	{
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a==-1&&b==-1&&c==-1)
	{
		break;
	}
	if(a==-1||b==-1)
	{
		printf("F\n");
		continue;
	}
	
	e=a+b;
	if(e>=80)
	{
		printf("A\n");
		continue;
	}
	else if(e>=65)
	{
		printf("B\n");
		continue;
	}
	else if(e>=50||c>=50)
	{
		printf("C\n");
		continue;
	}
	else if(e>=30)
	{
		printf("D\n");
		continue;
	}
	else if(e<30)
	{
		printf("F\n");
		continue;
	}	
	}
}


Measured memory_bytes: 2060
use std::io;

fn main() {
    let numbers = input_5_number();
    let w = numbers[0];
    let h = numbers[1];
    let x = numbers[2];
    let y = numbers[3];
    let r = numbers[4];

    if x - r < 0 {
        println!("No");
        return;
    }

    if y - r < 0 {
        println!("No");
        return;
    }

    if w < x + r  {
        println!("No");
        return;
    }

    if h < y + r {
        println!("No");
        return;
    }

    println!("Yes");
}

#[allow(dead_code)]
fn input_5_number() -> [i32; 5] {
    let mut input = String::new();

    io::stdin().read_line(&mut input)
        .expect("Failed to read line");

    let vec: Vec<&str> = input.split_whitespace().collect();

    let input1: i32 = vec[0].parse().unwrap_or(0);
    let input2: i32 = vec[1].parse().unwrap_or(0);
    let input3: i32 = vec[2].parse().unwrap_or(0);
    let input4: i32 = vec[3].parse().unwrap_or(0);
    let input5: i32 = vec[4].parse().unwrap_or(0);

    [input1, input2, input3, input4, input5]
}



Measured memory_bytes: 5024
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>


void test_case()
{
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n], b[m];
    for(ll i=0; i<n; i++) cin >> a[i];
    for(ll i=0; i<m; i++) cin >> b[i];
    ll currsum=0, i;
    
    for(i=0;i<n;i++) {
        if(currsum+a[i] <= k)
            currsum+=a[i];
        else break;
    }
    ll j=0, maxlen=i;

    while(i>=1 || j<m) {
        if(j<m && currsum+b[j]<=k) {
            currsum+=b[j];
            j++;
        }
        else if(i>=1) {
            currsum-=a[i-1];
            i--;
        } else break;
        maxlen = max(maxlen, i+j);
    }
    cout<<maxlen;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}


Measured memory_bytes: 6748
n = input()
l = map(int, raw_input().split())
max = l[0]
min = l[0]
s = l[0]
k = 1
while k < n:
    if max < l[k]:
        max = l[k]
    if min > l[k]:
        min = l[k]
    s = s + l[k]
    k = k + 1
print min, max, s

Measured memory_bytes: 7020
import sys
import numpy as np

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    a_s = LI()
    a_s = np.array(a_s)
    i_s = np.argsort(a_s)
    ans = [str(i + 1) for i in i_s]
    print(" ".join(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 23348
#include <stdio.h>
#pragma warning(disable:4996)

int a[100001], stts[100001];
int main() {
	int n;
	scanf("%d", &n);

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

	int cnt = 0, pt = 1;
	while(pt!=2 && stts[pt]!=1){
		stts[pt] = 1;
		pt = a[pt];
		cnt++;
	}

	if (pt==2) {
		printf("%d\n", cnt);
	}
	else {
		printf("-1\n");
	}

	return 0;
}

Measured memory_bytes: 896
a, b, c, d = map(int, input().split())

list1 = [a, b]
list2 = [c, d]

max = list1[0] * list2[0]

for n1 in list1:
  for n2 in list2:
    if max < (n1 * n2):
      max = n1 * n2

print(max)

Measured memory_bytes: 9172