akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[200005];
int judge(char a){
    if(a=='R') return 1;
    else if(a=='W') return 0;
}
int main(){
    int n,ans=0;cin>>n;
    scanf("%s",s+1);
    for(int i=1,j=n;;){
        if(i>=j)break;
        //cout<<i<<j<<endl;
        if(s[i]=='W'&&s[j]=='R'){
            s[i]='R',s[j]='W',i++,j--,ans++;
        }
        else if(s[i]=='R') i++;
        else if(s[j]=='W') j--;
        //if(i>=j)break;
        //cout<<i<<j<<endl;
    }
//    for(int i=1;i<=n;i++) cout<<s[i];
//    puts("");
    int l[200005]={0},r[200005]={0};
    for(int i=1;i<=n;i++){
        if(!judge(s[i])) l[i]++;
        l[i]+=l[i-1];
    }
    for(int i=n;i>=1;i--){
        if(judge(s[i])) r[i]++;
        r[i]+=r[i+1];
    }
    int sum=n;
    for(int i=1;i<=n;i++){
        if(judge(s[i])) sum=min(sum,l[i]+r[i+1]);
        else  sum=min(sum,l[i-1]+r[i]);
    }
    cout<<ans+sum;
}
/*
6
RWWRRR
6
RWWWRR
*/


Measured memory_bytes: 5516
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;
typedef deque<int> vi;
const int INF=1<<30;
int main() {
	int m,n,times[1000]={},now=0,tmp;
	cin >> n >> m;
	vi a,b;
	REP(i,n){
	cin >> tmp;
	a.push_back(tmp);
	}
	REP(i,m){
	cin >> tmp;
	b.push_back(tmp);
	}
	sort(b.begin(),b.end(),greater<int>());
	REP(i,m){
	while(!( b[i]>=a[now])) now++;
		times[now]++;
	}
	int maxim=0;
	REP(i,n)
		if(times[i]>times[maxim])
		maxim=i;
	cout << maxim+1 << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    string str;
    cin >> str;
    vector<int> date;
    string tmp = "";
    for(int i = 0; i < str.size(); i++){
        if(str[i] == '/'){
            int a = stoi(tmp);
            date.push_back(a);
            tmp = "";
        } else {
            tmp += str[i];
        }
    }
    string ans = "";
    if(date[0] > 2019){
        ans = "TBD";
    } else if(date[0] == 2019){
        if(date[1] > 4){
            ans = "TBD";
        } else if(date[1] == 4){
            ans = "Heisei";
        } else {
            ans = "Heisei";
        }
    } else {
        ans = "Heisei";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void solve(vector<int>& num, int i, int n)
{
    if(n < 0)
        return;
    if(n == 0){
        cout << num[0];
        for(int j=1; j<i; ++j)
            cout << ' ' << num[j];
        cout << endl;
        return;
    }

    int m = num.size();
    for(int j=(i==0?n:num[i-1]); j>0; --j){
        num[i] = j;
        solve(num, i+1, n-j);
    }
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> num(n);
        solve(num, 0, n);
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll T[105000];
ll A[105000];
ll maxi[105000];
ll B[105000];
const ll mod = 1e9+7;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> T[i];
    for(int i = 1; i <= N; i++) cin >> A[i];
    B[1] = T[1];
    B[N] = A[N];
    if(T[N] != A[1]) {
        cout << 0 << endl;
        return 0;
    }
    for(int i = 2; i <= N; i++) {
        if(T[i] == T[i-1]) continue;
        if(B[i] != 0 && B[i] != T[i]) {
            cout << 0 << endl;
            return 0;
        }
        B[i] = T[i];
    }
    for(int i = 1; i <= N - 1; i++) {
        if(A[i] == A[i+1]) continue;
        if(B[i] != 0 && B[i] != A[i]) {
            cout << 0 << endl;
            return 0;
        }
        B[i] = A[i];
    }
    for(int i = 1; i <= N; i++) {
        if(T[i] < B[i]) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = N; i >= 1; i--) {
        if(A[i] < B[i]) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    for(int i = 1; i <= N; i++) {
        maxi[i] = 1e9;
        if(B[i] != 0) {
            continue;
            chmin(maxi[i], B[i]);
        }
        chmin(maxi[i], T[i]);
        chmin(maxi[i], A[i]);
        ans *= maxi[i];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var ans = "No";
            var s = IO.GetString().ToCharArray();
            var num = s.Distinct().Count();
            if (num == 2)
            {
                var s0 = s[0];
                ans = s.Count(c => c == s0) == 2 ? "Yes" : ans;
            }
            
            Console.WriteLine(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
// ミント
const int mod = //1e9+7 ;
  998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
}   c(200005);
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 
 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }


int main(){
   ll n ; cin>> n ;
   vector<ll> A(n) ; rep(i,n) cin>>A[i] ;
   sort(A.begin(),A.end()) ;
   mint ans = A[0] ;
   rep2(i,1,n-1){
     mint x = gcd(A[i],i) ;
     ans *= x ;
   } 
   cout<<ans<<endl ;
    return 0;
  }
   



Measured memory_bytes: 7140
#include <iostream>
#include <unordered_map>
#include <cmath>

void FactrizePrime(int x, std::unordered_map<int, int> &count)
{
    while (x % 2 == 0)
    {
        ++count[2];
        x /= 2;
    }
    for (int i = 3; i <= x; i += 2)
    {
        while (x % i == 0)
        {
            ++count[i];
            x /= i;
        }
    }
}

constexpr int32_t MOD = 1000000007;

int main()
{
    int n;
    std::cin >> n;
    if (n == 1 || n == 2)
    {
        std::cout << n << std::endl;
        return 0;
    }

    std::unordered_map<int, int> factor;
    for (int i = 2; i <= n; ++i)
    {
        FactrizePrime(i, factor);
    }

    int64_t count = 1;
    for (const auto &p : factor)
    {
        count *= p.second + 1;
        count %= MOD;
    }

    std::cout << count << std::endl;
    return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m;
	cin>>n>>m;
	if(m/2<n)
	printf("%lld\n",m/2);
	else
	{
		printf("%lld\n",n+(m-2*n)/4);
	}
	return 0;
}

Measured memory_bytes: 256
for _ in range(int(input())):
	n=int(input())
	*a,=map(int,input().split())
	s=input()
	b=[]
	f=0
	for x,c in zip(a[::-1],s[::-1]):
		for y in b:
			x=min(x,x^y)
		if x:
			if c=="1":
				f=1
				break
			b.append(x)
	print(f)

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

int main() {

  int N, X;
  cin >> N >> X;
  int d = 0;
  int ans = 1;
  for(int i=0;i<N;i++) {
    int y;
    cin >> y;
    d += y;
    if(d <= X) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll INF = 1e9 + 7;
int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    if(H % h == 0 && W % w == 0)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    for(int i = 1; i <= H; i++)
    {
        for(int j = 1; j <= W; j++)
        {
            if(i % h == 0 && j % w == 0) cout << -(h*w-1) * 1000 -1 << " ";
            else cout << "1000 ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3680
#include<stdio.h>
struct date{
    int month,day;
};
int main(void){
    struct date date1, date2;
    scanf("%d %d %d %d",&date1.month,&date1.day,&date2.month,&date2.day);
    if(date2.day == 1){
        if(date1.month +1 == date2.month || (date1.month == 12 &&date2.month ==1))
            printf("1");
    }
    else printf("0");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    ll k, a, b;
    cin >> k >> a >> b;
    string ans = "NG";
    for (int i = a; i <= b; i ++) {
    	if (i % k == 0) {
    		ans = "OK";
	    }
    }
    cout << ans;
    return (0);
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int n; cin >> n;
    int abc[n][3];
    rep(i,n) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];

    int dp[n][3];
    rep(i,n)rep(j,3) dp[i][j]=0;

    rep(i,3) dp[0][i]=abc[0][i];
    for(int i=1; i<n; i++){
        rep(j,3){
            rep(k,3){
                if(j==k) continue;
                dp[i][j]=max(dp[i-1][k]+abc[i][j],dp[i][j]);
            }
        }
    }
    int ans=0;
    rep(i,3) ans=max(ans,dp[n-1][i]);

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

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) {x = x * 10 + c - '0', c = getchar();}
	return x * f;
}

const int maxn = 1e5 + 10;
vector<int> linker[maxn], d;
int n, p[maxn], k[maxn], mark[maxn], mx[maxn], dep[maxn], ans[maxn];

void upd()
{
	bool flag = 0;
	for (int i = 1; i <= n; i ++)
		if (ans[i] != p[i])
		{
			if (p[i] < ans[i])
			{
//				cerr << "debug " << i << " " << p[i] << " " << ans[i] << endl;
				flag = 1;
			}
			break;
		}
	if (!flag) return;
	for (int i = 1; i <= n; i ++) ans[i] = p[i];
}

void dfs(int x, int fa)
{
	dep[x] = dep[fa] + 1, mx[x] = x;
	for (int cur : linker[x])
		if (cur != fa)
		{
			dfs(cur, x);
			if (dep[mx[cur]] > dep[mx[x]])
				mx[x] = mx[cur];
		}
}

int Getroute(int x, int fa, int tail)
{
	if (x == tail)
	{
		d.push_back(x);
		return 1;
	}
	for (int cur : linker[x])
		if (cur != fa)
		{
			bool f = Getroute(cur, x, tail);
			if (f)
			{
				d.push_back(x);
				return 1;
			}
		}
	return 0;
}

void operate(int l, int r)
{
	if (l == r) return;
	int x = p[l];
	for (int i = l; i < r; i ++) p[i] = p[i + 1];
	p[r] = x;
}

void Solve()
{
	for (int i = 1; i <= n; i ++) p[i] = i;
	int s = 0;
	for (int cur : d)
	{
		operate(s + 1, s + k[cur] + 1);
		s += k[cur] + 1;
	}
//	for (int i = 1; i <= n; i ++)
//		printf("%d ", p[i]); puts("");
	upd();
}

int main()
{
	n = read();
	for (int i = 1; i < n; i ++)
	{
		int u = read(), v = read();
		linker[u].push_back(v);
		linker[v].push_back(u);
	}
	dfs(1, 0);
	int head = mx[1];
	dfs(head, 0);
	int tail = mx[head];
	Getroute(head, 0, tail);
	for (int cur : d) mark[cur] = 1;
	for (int x = 1; x <= n; x ++) if (!mark[x])
	{
		bool f = 0;
		for (int cur : linker[x])
			if (mark[cur]) {f = 1, ++ k[cur]; break;}
		if (!f) return puts("-1"), 0;
	}
	for (int i = 1; i <= n; i ++) ans[i] = n;
	Solve(), reverse(d.begin(), d.end()), Solve();
	for (int i = 1; i <= n; i ++) printf("%d%c", ans[i], i == n ? 10 : 32);
	return 0;
}

Measured memory_bytes: 14968
#include <iostream>
#include <stack>
#include <iterator>
#include <algorithm>

#define MAX_N 15
#define MAX_M 15000000


std::stack<int> trays[3];
std::stack<int> r_trays[3];

void moveTop(int i, int j) {
  // move top value i to j
  trays[j].push(trays[i].top());
  trays[i].pop();
}

void clearTray() {
  for (int i = 0; i < 3; i ++) {
    while(!trays[i].empty())
      trays[i].pop();
    while(!r_trays[i].empty())
      r_trays[i].pop();
  }
}

bool isEmpty() {
  if((trays[0].empty() && trays[1].empty()) || (trays[1].empty() && trays[2].empty()))
    return true;
  else
    return false;
}

int moveCups(int m) {
  int move = 0;
  bool flag = true;

  if (isEmpty())
    return 0;

  while(flag) {
    for (int i = 0; i < 2; i ++) { 
      move ++;
      // move bigger cup
      if (trays[i + 1].empty() || (!trays[i].empty() && trays[i].top() > trays[i + 1].top())) {
        moveTop(i, i + 1); 
      } else {
        moveTop(i + 1, i);
      }
      // check situation
      if (isEmpty()) {
        flag = false;
        break;
      } else if (move >= m) {
        flag = false;
        move = -1;
        break;
      }
    }
  }
  return move;
}

int main() {
  int n, m;
  int num, temp, move, left, right, ans;
  bool flag = true;
  while (1) {
    std::cin >> n >> m;
    if (n == 0)
      break;
    // store cups to trays.
    for (int i = 0; i < 3; i ++) {
      std::cin >> num;
      for (int j = 0; j < num; j ++) {
        std::cin >> temp;
        trays[i].push(temp);
      }
      r_trays[2 - i] = trays[i];
    }
    std::reverse(std::begin(r_trays), std::end(r_trays));
    right = moveCups(m);
    for (int i = 0; i < 3; i ++)
      trays[i].swap(r_trays[2 - i]);
    left = moveCups(m);

    if (right != -1 && left != -1)
      ans = right < left ? right : left;
    else
      ans = right > left ? right : left;
    std::cout << ans << std::endl;
    clearTray();
  }
  return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

bool tate[100];
bool yoko[100];


int main(){
	int h, w;
	cin >> h >> w;
	char stage[100][100];
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin >> stage[i][j];
		}
	}

	for (int i = 0; i < h; i++){
		int coun = 0;
		for (int j = 0; j < w; j++){
			if (stage[i][j] == '.') coun++;
		}
		if (coun == w) yoko[i] = true;
	}

	for (int i = 0; i < w; i++){
		int coun = 0;
		for (int j = 0; j < h; j++){
			if (stage[j][i] == '.') coun++;
		}
		if (coun == h) tate[i] = true;
	}

	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (!yoko[i] && !tate[j]) cout << stage[i][j];
		}
		if (!yoko[i]) cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
using namespace std;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

  auto ds = divisor(M);
  int max = M / N;
  int ans = *(upper_bound(ALL(ds), max) - 1);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <climits>

//find out the use of the below
#include <list>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
vector<int> g[(int)1e5+5];
vector<int> gp[(int)1e5+5];

int pr[(int)1e5+5];
int dfs(int u, vector<int>* g){
    if (pr[u] != 0)
        return pr[u];
    int ans = 0;
    for (int v: g[u]){
        ans = max(dfs(v, g), ans);
    }
    return pr[u] = ans+1;
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; ++i){
        int x, y;
        scanf("%d%d", &x, &y);
        g[x].pb(y);
        gp[y].pb(x);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i){
        if (pr[i+1] == 0){
            ans = max(ans, dfs(i+1, g));
        }
    }
    MEMS(pr);
    for (int i = 0; i < n; ++i){
        if (pr[i+1] == 0){
            ans = max(ans, dfs(i+1, gp));
        }
    }
    cout << ans-1; 
    return 0;
}
/* BEFORE submitting, check for:
 *  1. Integer overflow
 *  2. Float/Double precision errors
 *  3. Array index out of bounds
 *  4. Edge cases.(n=1, n=max, etc.)
 *  5. Time complexity. No TLEs
 */



Measured memory_bytes: 13696
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100005
#define M 200005
#define LL long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mi d + 1, r
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MP make_pair
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
inline int sgn(double x){return (x > EPS) - (x < -EPS);}
//struct EE{int v, w, nx;}E[M * 2 + N * 2]; int hd[N], EN;
//void init_edge(int num){EN = 0; memset(hd, -1, (num + 3) << 2);}
//void add_edge(int u, int v, int w){
//    E[EN].w = w; E[EN].v = v; E[EN].nx = hd[u]; hd[u] = EN++;
//    E[EN].w = w; E[EN].v = u; E[EN].nx = hd[v]; hd[v] = EN++;
//}
//const int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
int n;
long long A, B;
long long a[N];
long long aa[N];
bool ok(long long c){
    FF(i, 1, n) a[i] = aa[i];
    FF(i, 1, n){
        a[i] -= B * c;
    }
    long long s = 0;
    FF(i, 1, n) if(a[i] > 0){
        s += (a[i] - 1) / (A - B) + 1;
    }
    if(s > c) return 0;
    return 1;
}
int main(){
   // IN;
    SC(n);
    scanf("%lld%lld", &A, &B);
    FF(i, 1, n)scanf("%lld", &aa[i]);
    long long L = 1, R = 1000000000;
    while(L <= R){
        long long mid = L + (R - L) / 2;
        if(mid == 1){
            ++L;
            --L;
        }
        if(ok(mid)) R = mid - 1;
        else L = mid + 1;
    }
    printf("%lld\n", L);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int M;
int C;
int B[114];

int main() {
  scanf("%d%d%d", &N, &M, &C);
  rep(i, M) {
    scanf("%d", &B[i]);
  }

  int ans = 0;
  rep(i, N) {
    int c = C;
    rep(j, M) {
      int A;
      scanf("%d", &A);
      c += A*B[j];
    }
    if (c > 0) ans++;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long int
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
}
void printMp(mp m)
{
  mp ::iterator it;
  for(it=m.begin();it!=m.end();it++)cout<<it->first<<' '<<it->second<<endl;
}
void printUmp(ump m)
{
  ump ::iterator it;
  for(it=m.begin();it!=m.end();it++)cout<<it->first<<' '<<it->second<<endl;
}
void printSt(st s)
{
  st ::iterator it;
  for(it=s.begin();it!=s.end();it++)cout<<*it<<' ';
}
void printMst(mst s)
{
  mst ::iterator it;
  for(it=s.begin();it!=s.end();it++)cout<<*it<<' ';
}
void printVec(vector<int>v)
{
for(int i=0;i<v.size();i++)cout<<v[i]<<' ';
}
void printVec2(vector<int>v[],int n)
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<v[i].size();j++)
            cout<<v[i][j]<<' ';
        cout<<endl;
    }
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
int32_t main()
{
fastio;
int a;in a;string s;in s;
if(a>=3200) out s;else out "red";
 return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import os
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#############################################
s=input()
ans="Yes"
for a in range(0,len(s),2):
  if len(s)-1==a or (not s[a:a+2]=="hi"):
  	ans="No"
print(ans)


Measured memory_bytes: 6768
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_JOB_MAX		200000									// 最大仕事数

// 内部構造体 - 仕事情報
typedef struct Job {
	int miTime;													// 必要時間
	int miEnd;													// 終了時間
} Job;

// 内部変数
static FILE *szpFpI;											// 入力
static Job sz1Job[D_JOB_MAX];									// 仕事
static int siJCnt;												// 仕事数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// 出力
int
fOut(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ソート関数 - 終了時間昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	Job *lzpVal1 = (Job *)pzpVal1;
	Job *lzpVal2 = (Job *)pzpVal2;

	// 終了時間昇順
	if (lzpVal1->miEnd > lzpVal2->miEnd) {
		return 1;
	}
	else if (lzpVal1->miEnd < lzpVal2->miEnd) {
		return -1;
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 仕事数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siJCnt);

	// 仕事 - 取得
	for (i = 0; i < siJCnt; i++) {
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &sz1Job[i].miTime, &sz1Job[i].miEnd);
	}

	// 仕事 - ソート
	qsort(sz1Job, siJCnt, sizeof(Job), fSortFnc);

	// 仕事 - 実行
	int liTime = 0;
	for (i = 0; i < siJCnt; i++) {
		liTime += sz1Job[i].miTime;
		if (liTime > sz1Job[i].miEnd) {
			return -1;
		}
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	if (liRet == 0) {
		sprintf(lc1Buf, "Yes\n");
	}
	else {
		sprintf(lc1Buf, "No\n");
	}
	fOut(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 3324
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
mlmis = lambda: [-int(x) for x in input().split()]
INF = float('inf')
#

def main():
    N = ii()
    A = lmis()
    S = sum(A)
    ans = INF
    s = 0
    for a in A:
        s += a
        ans = min(ans, abs((S-s)-s))
    print(ans)


main()


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

#define maxn 100000
#define read(x) scanf("%d",&x)

int n;
int a[maxn+5];

int main() {
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);
	
	int l=0,ans=0;
	for(int i=1;i<=n;i++) {
		if(a[i]<=a[i-1]) l++;
		else {
			ans=max(ans,l);
			l=0;
		}
	}
	
	ans=max(ans,l);
	printf("%d",ans);
	
	return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N, T;
	cin >> N >> T;
	int l = INF, s = 0;
	vector< pair<int, int> > apple;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a - l >= s) {
			if (a - l > s)apple.clear();
			s = a - l;
			apple.push_back({ l,a });
		}
		l = min(a, l);
	}
	cout << apple.size() << endl;
	return 0;
}

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

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

const int lim = 1000000007;

int main(){
    int N, Y;
    cin >> N >> Y;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            if(i + j > N) break;
            int k = N - (i + j);
            if(i * 10000 + j * 5000 + k * 1000 == Y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

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

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi std::vector<int>
#define vvi std::vector<std::vector<int> >
#define vpi std::vector<pi >
#define pi std::pair<int,int>
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (int var = (from); var <= ((int)(to)); var++)
#define DOWNTO(var, from, to) for (int var = (from); var >= ((int)(to)); var--)
#define FOR(var, to)		  UPTO(var, 0, (to)-1)
#define DOWN(var, from)	   DOWNTO(var, (from)-1, 0)

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) std::cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) std::cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static const int MOD = 1000000007;
static const int INF = ((1<<30)-1);
static const s64 LINF = ((1LL << 62)-1);

struct Comb {
	std::vector<std::vector<s64> > a;
	Comb(int n) { // O(n^2)
		a.resize(n+1);
		FOR(i,n+1) {
			a[i].resize(i+1, 1);
			UPTO(j,1,i-1) a[i][j] = a[i-1][j] + a[i-1][j];
		}
	}
	s64 ncr(int n, int r) {
		assert(n >= 0);
		assert(n <= (int)a.size());
		assert(r >= 0);
		assert(r <= n);
		return a[n][r];
	}
};

#define gc(c) (c)=getchar()
int ri() {
	int c,s=0,r=0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}
s64 rs64() {
	s64 r = 0;
	int c,s = 0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}

int int_less(const void *a, const void *b) {
	return (*(const int*)a - *(const int*)b);
}
int int_greater(const void *a, const void *b) {
	return (*(const int*)b - *(const int*)a);
}
std::string operator*(const std::string &s, int n){ std::string res; FOR(i,n) res += s; return res; }

template<class T> std::ostream& operator<<(std::ostream& os, std::vector<T> a) { for (auto i : a) os << i << " "; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, std::set<T> a) { for (auto i : a) os << i << " "; return os; }
template<class A, class B> std::ostream& operator<<(std::ostream&os, std::pair<A,B> a) { os << a.fi << "," << a.se; return os; }


int main() {
	int a = ri();
	int b = ri();
	int c = ri();
	int d = ri();
	long long res = 0;
	FOR(i,3001) FOR(j, 3001) {
		int left = d - a * i - b * j;
		if (left < 0 || left % c) continue;
		res++;
	}
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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

int main(){fastio
    ll n;cin>>n;
    string s;cin>>s;
    ll p[1<<(n+1)];
    rep(i,0,(1<<n)-1){
        cin>>p[i];
        p[i]--;
    }
    rep(i,0,(1<<n)-1){
        p[i+(1<<n)]=p[i];
    }
    ll dp[1<<n][n+1];
    rep(j,0,n){
        if(j==0){
            rep(i,0,(1<<n)-1){
                dp[i][j]=p[i];
            }
        }else{
            rep(i,0,(1<<n)-1){
                ll x=dp[i][j-1];
                ll posy=(i+(1<<(j-1)))&((1<<n)-1);
                ll y=dp[posy][j-1];
                if(x>y)swap(x,y);
                if(s[y-x-1]=='0'){
                    dp[i][j]=x;
                }else{
                    dp[i][j]=y;
                }
            }
        }
    }
    rep(i,0,(1<<n)-1){
        cout<<dp[i][n]+1<<endl;
    }
    
    
    return 0;
}



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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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 int MOD = 1000000007;

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

    int n = s.size();
    char p = s[0];
    int c = 0;
    FOR(i, 1, n) {
        if (s[i] == p) {
            if (i == n - 1) break;
            c++;
            i++;
            p = '0';
        } else {
            c++;
            p = s[i];
        }
    }

    cout << c + 1 << endl;
}

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

int main() {
  int N, S;
  S = 0;
  cin >> N;

  for(int i=0; i<N; i++){
    int l, r;
    cin >> l >> r;

    S += r-l+1;
    }

  cout << S << endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG 

int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    vector<int> srt={A,B,C,D};
    sort(srt.begin(),srt.end());
    int count=0;
    if(B<=C||A>=D) cout<<count<<endl;
    else{
        count=srt[2]-srt[1];
        cout<<count<<endl;
    }
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  if(a>12) cout<<b<<endl;
  else if(a<6) cout<<0<<endl;
  else cout<<b/2<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main() {
	int n;
	for (int i = 1; ; i++) {
		cin >> n;
		if (n == 0) {
			break;
		}
		printf("Case %d:\n", i);
		vector< vector<int> > data(n, vector<int>(n, 0));
		int counter = 1;
		int x, y;
		x = y = 0;
		data[x][y] = counter;
		counter++;
		int f = 0;
		while (counter <= n*n) {
			if (f == 0 && x+1 < n) {
				x++;
				data[x][y] = counter;
				counter++;
				f = 1;
			} else if (f == 1 && x-1 >= 0 && y+1 < n && data[x-1][y+1] == 0){
				x--;
				y++;
				data[x][y] = counter;
				counter++;
				f = 1;
			} else if (f == 2 && y+1 < n) {
				y++;
				data[x][y] = counter;
				counter++;
				f = 4;
			} else if (f == 3 && x+1 < n) {
				x++;
				data[x][y] = counter;
				counter++;
				f = 4;

			} else if (f == 4 && x+1 < n && y-1 >= 0) {
				x++;
				y--;
				data[x][y] = counter;
				counter++;
				f = 4;
			} else {
				f++;
				if (f == 5) {
					f = 0;
				}
			}
		}
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				printf("%3d", data[k][j]);
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N;cin >>N;
    ll C;cin >>C;
    vector<ll> x(N),y(N);
    vector<ll> v(N),w(N);
    FOR(i,0,N) cin>>x[i]>>v[i];
    FOR(i,0,N){
        y[i]=C-x[N-i-1];
        w[i]=v[N-i-1];
    }
    vector<ll> S1(N+1),S2(N+1);S1[0]=0;S2[0]=0;
    FOR(i,0,N){
        S1[i+1]=S1[i]+v[i];
        S2[i+1]=S2[i]+w[i];
    }
    vector<ll> c1(N+1),c2(N+1);c1[0]=0;c2[0]=0;
    FOR(i,0,N){
        c1[i+1]=max(c1[i],S1[i+1]-x[i]);
        c2[i+1]=max(c2[i],S2[i+1]-y[i]);
    }
    x.insert(x.begin(),0);
  	y.insert(y.begin(),0);
    ll res=0;
    FOR(i,0,N+1){
        res=max(res,S1[i]+c2[N-i]-2*x[i]);
    }
  	FOR(i,0,N+1){
        res=max(res,S2[i]+c1[N-i]-2*y[i]);
    }
    cout << res << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define pb push_back
using ll = long long;
using P = pair<ll,ll>;
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; }

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  ll n, count=0, ans=0;
  string s;
 
  cin >> n;

  vector<P> a;

  rep(i,n){
    cin >> count;
    a.pb(make_pair(count,i+1));
  }

  sort( a.rbegin(), a.rend());

  
  vector<vector<ll>> dp(n+1,vector<ll>(n+1));
  dp[0][0]=0;//[左][右]
  rep2(i,n){
    dp[i][0]=dp[i-1][0] + a[i-1].first*(a[i-1].second - i);
    dp[0][i]=dp[0][i-1] + a[i-1].first*((n-i+1) - a[i-1].second);
  }
  
  rep2(i,n){
    rep2(l,n){
      if(i+l>n) continue;

      dp[i][l]=max(dp[i][l-1] + a[i+l-1].first*((n-l+1) - a[i+l-1].second),
                   dp[i-1][l] + a[i+l-1].first*(a[i+l-1].second - i));
    }
  } 

  rep(i,n+1){
    chmax(ans,dp[i][n-i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 34684
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	int N;
	cin>>N;
	
	vector<int> ans;
	
	int sum = 0;
	
	for(int i=1;i<=N;i++){
		ans.push_back(i);
		sum+=i;
		if(sum>=N)break;
	}
	
	for(int i=0;i<ans.size();i++){
		if(ans[i] == sum-N){
			ans.erase(ans.begin()+i);
			break;
		}
	}
	
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<endl;
	}
		
	
	return 0;
}

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

using namespace std;

int main()
{
   long long n,a,b,c,sum=0;
   cin>>n;
   for(a=1;a<=n;a++)
   {
      for(b=1;b<=n;b++)
      {
         for(c=1;c<=n;c++)
         sum+=__gcd(__gcd(a,b),c);

      }
   }
   cout<<sum<<endl;


   return 0;

}


Measured memory_bytes: 3632
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
using namespace std;
const int MOD = (int)1e9+7;
void solve()
{
   ll n,m;
   cin>>n>>m;
   vector<ll>nums;
   ll sum=0;
   for(int i=1;i<=n;i++)
   {
     ll a;
     cin>>a;
     nums.push_back(a);
     sum+=a;
   }
   sort(nums.rbegin(),nums.rend());
   double lagbe=(1/(4*m*1.0))*(sum*1.0);
   int Count=0;
   for(int i=0;i<n;i++)
   {
     if(nums[i]>=lagbe){
      Count++;
      if(Count==m){
        cout<<"Yes"<<endl;
        return ;
      }
     }
   }
   cout<<"No"<<endl;
   return ;
}
int  main()
{
    IOS
    solve();
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

h, w = [int(i) for i in input().split()]
all_map = []
for _ in range(h):
    all_map.append([i for i in input()])
for i in range(h):
    for j in range(w):
        if all_map[i][j] == ".":
            counter = 0
            for c_height in range(max(0, i -1), min(h, i + 1 + 1)):
                for c_width in range(max(0, j -1), min(w, j + 1 + 1)):
                    if all_map[c_height][c_width] == "#":
                        counter += 1
            all_map[i][j] = counter
for item in all_map:
    print("".join([str(i) for i in item]))


Measured memory_bytes: 3064
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  getLine
  as <- map (read::String->Int) . words <$> getLine
  print $shiftonly 0 as

shiftonly x y = if all even y
                    then shiftonly (x+1) $ map (`div`2) y
                    else x

Measured memory_bytes: 4960
//sobskdrbhvk
//remember the flying, the bird dies ):(
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, ans = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		int x;
		cin >>x;
		ans += x&1;
	}
	cout << (ans & 1 ? "NO" : "YES");
	return 0;
}

Measured memory_bytes: 384