akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int t[n], x[n], y[n];
  int xy_sum[n];
  int i;
  for (i = 0; i < n; i++) {
    cin >> t[i] >> x[i] >> y[i];
    xy_sum[i] = x[i] + y[i];
  }

  bool can_trav = true;
  if (t[0] < xy_sum[0] || (t[0] + xy_sum[0]) % 2 != 0) {
    can_trav = false;
  }
  for (i = 1; i < n && can_trav; i++) {
    int time = t[i] - t[i - 1], distance = xy_sum[i] - xy_sum[i - 1];
    if (time < distance || (time - distance) % 2 != 0) {
      can_trav = false;
      break;
    }
  }
  cout << (can_trav ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;

int main(){
	long long n,p;
	cin >> n;
	long long min_now=0,cnt=0;
	for(long long i=0;i<n;i++){
		cin >> p;
		if(i==0 || min_now>p){
			min_now=p;
			cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=100010;
const int P=1000000007;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;//a-b昇順
}
//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ
//	cout<<(n-2)*180<<endl;
//	string s="hoge";
//	cout<<ans<<endl;
//	int  n  ,a  ,b  ,c  ,d  ,e  ,f  ;
//	cin  >>n  >>a  >>b  >>c  >>d  >>e  >>f  ;

/*
	memset(b, '\0', sizeof(b));
初期化*/


/*
	len = strlen(s);
文字列長さ*/


/*
	string s;
	s.size()
*/


/*ソート
	qsort(b, 10, sizeof(int), compare_int);
*/


/*
	char s[N];
	strlen(s)
/*
	if(  <  )puts("Yes");
	else puts("No");
*/
/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/

int main(){
	char s[110];
	cin>>s;
	int n=0;
	rep(i, strlen(s)){
		if((i%2==0&&s[i]=='L')||(i%2==1&&s[i]=='R')){
			n++;
		}
	}
	if( n ==0  )puts("Yes");
	else puts("No");




}
/*int main()
{
    char str1[] = "Kyoto";
    char str2[] = "Sangyo";
	char str3[22] "aaa";
	if(1){
	 str3 = "University";
	}
    printf("%s %s %s\n", str1, str2, str3);
    return 0;
}*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    int n,k;cin >> n >> k;
    vector<int> a(n);for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    vector<int> b;
    int x=1;
    for(int i = 1; i < n; i++) {
        if(a[i-1]==a[i]) x++;
        else {
            b.push_back(x);
            x=1;
        }
    }
    b.push_back(x);
    sort(b.begin(),b.end());
    int m=b.size();

    ll ans=0;
    int i=0;
    while(m>k){
        m--;
        ans += b[i];
        i++;
    }

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

Measured memory_bytes: 4860
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}

// BFSによる(隣接リスト)塗りつぶし探索
#define MAX_E (100000)
#define MAX_V (100000)
int V, E; // V:頂点数、E:辺数
vector<int> G[MAX_V]; // 隣接リストでグラフを保持
int arrow[MAX_V];
bool seen[MAX_V];

void bfs(int v) {

	// キューを用意して、初期探索点をセット
	queue <int> que;
	arrow[v] = -1;
	seen[v] = true;
	que.push(v);

	while (!que.empty()) { // BFSループ
		// ★★　この中で迂闊に break しないこと

		// キューの先頭のセルを取得
		int from = que.front(); que.pop();

		// 取得したセルに対する処理

		// そのセルからつながるセルに処理を移行
		for (int i = 0; i < G[from].size(); i++) {
			int to = G[from][i];

			if (!seen[to]) {
				arrow[to] = from; // 矢印をつける
				seen[to] = true;
				que.push(to);
			}
		}
	}
}

int main() {

	cin >> V; //頂点
	cin >> E; //辺

	for (int i = 0; i < E; i++) {
		int a, b;
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1); // 無向グラフ
	}

	bfs(0);

	for (int i = 0; i < V; i++) {
		if (!seen[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	for (int i = 1; i < V; i++) {
		cout << arrow[i] + 1 << endl;
	}

	return 0;

}

Measured memory_bytes: 10508
#include <bits/stdc++.h>
#include <complex>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
#define INF 1e9
#define MOD 1e9 + 7
using namespace std;

template<typename T> void cmin(T &a, T b) { a = min(a, b); }
template<typename T> void cmax(T &a, T b) { a = max(a, b); }

using P = complex<double>;
const double PI = acos(-1);
// P p(a,b)=a+bi -> 点p(a,b)
namespace std {
  bool operator<(const P &a, const P &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); }
  bool operator==(const P &a, const P &b) { return a.real() == b.real() && a.imag() == b.imag(); }
} // namespace std
// i倍すれば反時計回りに90度回転
P turn(P p, double t) { // t度回転
  return p * exp(P(.0, t * PI / 180.0)); //ベクトルにe^θiをかける
}

signed main() {
  int n;
  while (cin >> n) {
    if (n == -1) break;
    P p(1, 0);
    rep(i, n - 1) {
      P t = p * P(0, 1);
      t = t / abs(t);
      p = p + t;
    }
    cout << p.real() << endl;
    cout << p.imag() << endl;
  }
  return 0;
}



Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

// const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
const ll MAX_SIZE = 1000005;

ll ss[MAX_SIZE];
int main() {
    init();
    ll N;
    cin >> N;
    string S;
    cin >> S;
    if(N==2){
        cout<<abs(S[0]-S[1])<<endl;
        return 0;
    }
    rep(i, N - 1) ss[i] = abs(S[i] - S[i + 1]);
    ll cnt = 0, cnt2 = 0;
    bool one=false, two=false;
    rep(i,N-1){
        if (ss[i] == 1){
            (cnt += (N-2==(i | N-2-i))) %= 2, one = true;
        }
        else if(ss[i]==2)
            two = true, (cnt2 += (N - 2 == (i | N - 2 - i))) %= 2;
    }

    if(two==false){
        cout << cnt << endl;
    }
    else if(one){
        cout << cnt << endl;
    }
    else{
        cout << (cnt2 %2 ? 2 : 0) << endl;
    }
    
}

Measured memory_bytes: 9244
# ABC128C - Switches
from itertools import product

n, m = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
con = list(map(int, input().rstrip().split()))
ans = 0
for i in product(range(2), repeat=n):
    cnt = 0
    for j in range(m):
        ons = 0
        for k in lst[j][1:]:
            if i[k - 1] == 1:
                ons += 1
        if ons % 2 == con[j]:
            cnt += 1
    if cnt == m:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v) for (auto &&V : v)
#define all(x) (x).begin(), (x).end()
using lint = long long;
const int INF = 1 << 29;
const double EPS = 1e-9;
using namespace std;

int main(void) {
  int m, k;
  cin >> m >> k;
  bool ok = true;
  int max = 1;
  for (int i = 0; i < m; ++i) {
    max *= 2;
  }
  if (k >= max) {
    ok = false;
  }
  if (m < 2) {
    if (k == 0) {
      rep(i, max) cout << (i != 0 ? " " : "") << i;
      rrep(i, max) cout << " " << i;
      return 0;
    }
    ok = false;
  }
  if (ok) {
    cout << k;
    rep(i, max) if (i != k) cout << " " << i;
    cout << " " << k;
    rrep(i, max) if (i != k) cout << " " << i;
  } else {
    cout << -1;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
  int y;
  cin >> y;
  vector<int> x(4);
  rep(i,4){
    x.at(i) = y%10;
    y /= 10;
  }
  reverse(x.begin(),x.end());
  if(x.at(0)-x.at(1)-x.at(2)-x.at(3) == 7){
    cout << x.at(0)<<"-"<<x.at(1)<<"-"<<x.at(2)<<"-"<<x.at(3)<<"=7"<< endl;
    return 0;
  }
  if(x.at(0)-x.at(1)-x.at(2)+x.at(3) == 7){
    cout << x.at(0)<<"-"<<x.at(1)<<"-"<<x.at(2)<<"+"<<x.at(3)<<"=7"<< endl;
    return 0;
  }
  if(x.at(0)-x.at(1)+x.at(2)-x.at(3) == 7){
    cout << x.at(0)<<"-"<<x.at(1)<<"+"<<x.at(2)<<"-"<<x.at(3)<<"=7"<< endl;
    return 0;
  }
  if(x.at(0)-x.at(1)+x.at(2)+x.at(3) == 7){
    cout << x.at(0)<<"-"<<x.at(1)<<"+"<<x.at(2)<<"+"<<x.at(3)<<"=7"<< endl;
    return 0;
  }
  if(x.at(0)+x.at(1)-x.at(2)-x.at(3) == 7){
    cout << x.at(0)<<"+"<<x.at(1)<<"-"<<x.at(2)<<"-"<<x.at(3)<<"=7"<< endl;
    return 0;
  }
  if(x.at(0)+x.at(1)-x.at(2)+x.at(3) == 7){
    cout << x.at(0)<<"+"<<x.at(1)<<"-"<<x.at(2)<<"+"<<x.at(3)<<"=7"<< endl;
    return 0;
  }
  if(x.at(0)+x.at(1)+x.at(2)-x.at(3) == 7){
    cout << x.at(0)<<"+"<<x.at(1)<<"+"<<x.at(2)<<"-"<<x.at(3)<<"=7"<< endl;
    return 0;
  }
  if(x.at(0)+x.at(1)+x.at(2)+x.at(3) == 7){
    cout << x.at(0)<<"+"<<x.at(1)<<"+"<<x.at(2)<<"+"<<x.at(3)<<"=7"<< endl;
    return 0;
  }
}


Measured memory_bytes: 3604
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli A[100010] = {};
lli B[100010] = {};

int main(void) {

	lli N;
	cin >> N;

	FOR(N + 1)
		cin >> A[i];
	FOR(N)
		cin >> B[i];

	lli sum = 0;

	for (int i = 0; i < N; i++) {
		{
			lli t = min(A[i], B[i]);
			sum += t;
			A[i] -= t;
			B[i] -= t;
		}
		{
			lli t = min(A[i + 1], B[i]);
			sum += t;
			A[i + 1] -= t;
			B[i] -= t;
		}
	}

	COUT(sum);

	return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n,wei;
    int maxv=-1;
    int v[105]={};
    int w[105]={};
    cin>>n>>wei;
    REP(i,n)cin>>v[i]>>w[i];

    int mat[105][10005];
    REP(i,105)REP(j,10005)mat[i][j]=-(1<<30);
    mat[0][0]=0;
    REP(i,n)REP(j,wei+1){
        if(j<w[i])mat[i+1][j]=mat[i][j];
        else mat[i+1][j] = max(mat[i][j], mat[i+1][j-w[i]]+v[i]);
        if(maxv<mat[i+1][j])maxv=mat[i+1][j];
    }
    cout<<maxv<<endl;
    return 0;
}


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

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int64_t ans = 0;
    for(int r=0; r<=N; r++) for(int g=0; g<=N; g++){
        int b = N-r*R-g*G;
        if(b >= 0 && b%B == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int N, L;
    cin >> N >> L;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    int pos;
    bool check = false;
    for (int i = 1; i < N; i++) {
        if (a[i-1]+a[i] >= L) {
            check = true;
            pos = i;
            break;
        }
    }
    if (!check) {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    for (int i = 1; i < pos; i++) cout << i << endl;
    for (int i = N-1; i >= pos; i--) cout << i << endl;
    
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  vi a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(all(a));
  bool ans = (a[0] + a[1] == a[2]);
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#define N 50000
#define M 20
#define INF 1<<29
using namespace std;

int A[M+1];
int T[N+1];

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>A[i];
    }
    for(int i=0;i<=n;i++){
        T[i]=INF;
    }
    T[0]=0;
    for(int i=0;i<m;i++){
        for(int j=0;j+A[i]<=n;j++){
            T[j+A[i]]=min(T[j+A[i]],T[j]+1);
        }
    }
    cout<<T[n]<<endl;
    return 0;
}



Measured memory_bytes: 3288
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iK = int.Parse(sS[1]);
            sS = System.Console.ReadLine().Trim().Split(' ');
            List<decimal> lstInp = new List<decimal>();
            for (int i = 0; i < sS.Length; i++)
            {
                lstInp.Add(decimal.Parse(sS[i]) / 2M + 0.5M);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<decimal> lstSum = new List<decimal>();
            decimal iSum = 0M;
            lstSum.Add(iSum);
            for (int i = 0; i < lstInp.Count; i++)
            {
                iSum += lstInp[i];
                lstSum.Add(iSum);
            }
            List<decimal> lstRet = new List<decimal>();
            for (int i = 0; i <= lstInp.Count - iK; i++)
            {
                lstRet.Add(lstSum[i + iK] - lstSum[i]);
            }
            lstRet.Sort();

            // 出力
            System.Console.WriteLine("{0}", lstRet[lstRet.Count - 1].ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 45372
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>
#include<set>
#include<tuple>

using namespace std;
typedef pair<int,int> P;

int main(){
    int N,M;
    P fightX[100000];
    P fightY[100000];
    bool IsUsed[100000]={};
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int x,y;
        cin>>x>>y;
        fightY[i]=P(y,i);
        fightX[i]=P(x,i);
    }
    sort(fightY,fightY+M);
    sort(fightX,fightX+M);
    int Xind=0;
    int ans=0;
    for(int i=0;i<M;i++){
        int ind=fightY[i].second;
        if(!IsUsed[ind]){
            //ここの手前で橋を切断
            int seY=fightY[i].first;
            ans++;
            while(Xind<M && fightX[Xind].first<seY){
                IsUsed[fightX[Xind].second]=true;
                Xind++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <vector>
#include <queue>
using namespace std;
#define mod 1000000007
#define INF 0x7fffffffff
#define N 100100
#define endl '\n'
long long p[1000000],q[1000000];
long long sum[1000000];
int main()
{
    long long n,m;
    long long ans=0;
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++) scanf("%lld",&p[i]),ans+=p[i];
    for(int i=1;i<=m;i++) scanf("%lld",&q[i]),ans+=q[i];
    sort(q+1,q+m+1);
    sum[0]=0;
    for(int i=1;i<=m;i++) sum[i]=sum[i-1]+q[i];
    for(int i=1;i<=n;i++)
    {
        long long l=1,r=m,res=m;
        while(l<=r)
        {
            int mid=l+r>>1;
            if(q[mid]>p[i]) res=mid,r=mid-1;
            else l=mid+1;
        }
        if(q[res]<=p[i]) res++;
        ans=ans+sum[res-1]+(long long)p[i]*(m-res+1);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner; 
public class Main { 
    public static void main(String[] args) { 
        Scanner sc = new Scanner(System.in); 
        int n = sc.nextInt(); 
        for (int i = 3; i <= n; i++) { 
            int a = i;
            if (i % 3 == 0) { 
            System.out.print(" " + i); 
            continue; 
            } else { 
                while (a != 0) { 
                    if (a % 10 == 3) { 
                    System.out.print(" " + i); 
                    break; 
                    } 
                a = a / 10; 
                }
            } 
        } 
    System.out.println(""); 
    } 
}


Measured memory_bytes: 29072
#include <iostream>
#include <queue>
#define INF 1e+9
using namespace std;

typedef pair<int,int> P;

int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};

int main(){
	int w,h;
	while(1){
		bool field[30][30][4] = {};
		int d[30][30];
		cin >> w >> h;
		if(!w) break;
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++) d[i][j] = -1;
		}
		for(int i = 0;i < h * 2 - 1;i++){
			if(i % 2 == 0){
				for(int j = 0;j < w - 1;j++){
					int t;
					cin >> t;
					if(t) {
						field[i / 2][j][1] = true;
						field[i / 2][j + 1][3] = true;
					}
				}
			}
			else {
				for(int j = 0;j < w;j++){
					int t;
					cin >> t;
					if(t) {
						field[i / 2][j][2] = true;
						field[i / 2 + 1][j][0] = true;
					}
				}
			}
		}
		queue<P> que;
		d[0][0] = 0;
		que.push(P(0,0));
		for(int i = 0;;i++){
			int siz = que.size();
			if(siz == 0) break;
			for(int j = 0;j < siz;j++){
				P p = que.front();que.pop();
				for(int k = 0;k < 4;k++){
					int x = p.first + dx[k],y = p.second + dy[k];
					if(x >= 0 && x < h && y >= 0 && y < w && !field[p.first][p.second][k] && d[x][y] == -1){
						d[x][y] = i + 1;
						que.push(P(x,y));
					}
				}
			}
		}
		cout << d[h - 1][w - 1] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3024
use std::env;
use std::io::prelude::*;
use std::io;
use std::fs::File;
use std::str::FromStr;
use std::io::BufReader;
fn buf_read() -> io::Result<(Vec<String>)> {
    let args: Vec<_> = env::args().collect();
    if args.len() >= 2 {
        let f = try!(File::open("input.txt"));
        let input_lines: Vec<_> = BufReader::new(f).lines().collect();
        let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
        Ok((lines))
    } else {
        let stdin = io::stdin();
        let input_lines: Vec<_> = stdin.lock().lines().collect();
        let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
        Ok((lines))
    }
}

fn main() {
    let input = buf_read().unwrap();
    let input_str: Vec<String> = input[0].split(' ').map(String::from).collect();
    let mut input_num: Vec<i32> = vec![];
    for e in input_str {
        let num: i32 = i32::from_str(e.as_str()).unwrap();
        input_num.push(num);
    }
    if (input_num[0] + input_num[1] - input_num[2]) == 0 {
        println!("Yes")
    } else if input_num[0] - input_num[1] + input_num[2] == 0 {
        println!("Yes")
    } else if input_num[0] - input_num[1] - input_num[2] == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main() {
  int a, b;
  int ans = -200000;
  cin >> a >> b;
  ans = max(a + b, a * b);
  ans = max(ans, a - b);
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        long max = -1000001;
        long min = 1000001;
        for(int i = 0; i < n; i++){
            int a = sc.nextInt();
            sum += a;
            if(a > max){
                max = a;
            }
            if(a < min){
                min = a;
            }
        }
        System.out.println(min + " " + max + " " + sum);
    }
}


Measured memory_bytes: 42396
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = sorted([int(x) for x in input().strip().split()])
    maxi = max(A)
    mini = min(A)
    plus = [a for a in A[1:-1] if a >= 0]
    minus = [a for a in A[1:-1] if a < 0]
    print(maxi + sum(plus) - sum(minus) - mini)
    for p in plus:
        print(mini, p)
        mini -= p
    print(maxi, mini)
    maxi -= mini
    for m in minus:
        print(maxi, m)
        maxi -= m

if __name__ == '__main__':
    main()

Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    ll a[n];
    ll f[n+1];
    rep(i,n){
        scanf("%lld", &a[i]);
        f[a[i]] = i;
    }

    ll l[n+1] = {};
    ll l2[n+1] = {};
    ll r[n+1] = {};
    ll r2[n+1] = {};

    set<int> x;
    set<int> y;

    for(int i = n; i >= 1; i--){
        x.insert(-f[i]);
        y.insert(f[i]);
        auto ite = x.upper_bound(-f[i]);
        if(ite != x.end()){
            l[i] = -(*ite);
            ite = x.upper_bound(-l[i]);
            if(ite != x.end()){
                l2[i] = -(*ite);
            }else{
                l2[i] = -1;
            }
        }else{
            l[i] = -1;
            l2[i] = -1;
        }
        ite = y.upper_bound(f[i]);
        if(ite != y.end()){
            r[i] = *ite;
            ite = y.upper_bound(r[i]);
            if(ite != y.end()){
                r2[i] = *ite;
            }else{
                r2[i] = n;
            }
        }else{
            r[i] = n;
            r2[i] = n;
        }
    }

    ll ans = 0;

    srep(i,1,n+1){
        if(l[i]!=-1){
            ans += (l[i] - l2[i]) * (r[i] - f[i]) * i;
        }
        if(r[i]!=n){
            ans += (r2[i] - r[i]) * (f[i] - l[i]) * i;
        }
    }
    /*
    srep(i,1,n+1){
        cout << l2[i] << ' ' << l[i] << ' ' << f[i] << ' ' << r[i] << ' ' << r2[i] << endl;
    }
    */

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


Measured memory_bytes: 14336
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7;
ll OO=1e15;
const int N=1e3 + 5,M=1e5 + 3;
char arr[N][N];
ll dp[N][N];


ll n,m,k,cnt,SU,idx,len,MN,MX,T;
ll l,r,mid;
ll a,b,c,d;
vector<pair<int,pair<int,char>>> vec;
string str,t,ans;
bool flage;

bool valid(int x ,int y){
	return x>-1 && y>-1 && x<n && y<m && arr[x][y] != '#';
}

ll Solve(int x,int y){
	
	
	if(x == n-1 && y == m-1)
		return 1;
	
	ll &ret = dp[x][y];
	if(~ret)
		return ret;
	ret=0;
	
	if(valid(x+1,y))
		ret += Solve(x+1,y);
	
	if(valid(x,y+1))
		ret += Solve(x,y+1);
	

	return ret%MOD;
	
	
}


int main(){
	
	memset(dp,-1,sizeof dp);
	
	cin>>n>>m;
	for(int i=0;i<n;++i)
		cin>>arr[i];
	
	


	cout<<Solve(0,0)<<endl;
	
	


}



















Measured memory_bytes: 9216
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 
  
void lcs( string X, string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 

   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   int index = L[m][n]; 
  
   char lcs[index+1]; 
   lcs[index] = '\0'; 
  

   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; 
          i--; j--; index--;     
      } 
  
      
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   cout << lcs << endl; 
} 
  
int main() 
{ 
  string X,Y;
  cin >> X >> Y;
  int m = X.length();
  int n = Y.length(); 
  lcs(X, Y, m, n); 
  return 0; 
} 

Measured memory_bytes: 35456
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n){
    Int res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
    return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
Int extgcd(Int a, Int b, Int &x, Int &y) {
    Int g = a; x = 1; y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

int b[100005];
Int a[100005];
Int t[100005];
Int m[100005];


int main(){
    cin.tie(0);

    Int ans = 1;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> t[i];
        if (!i || t[i] != t[i-1]){
            b[i] = 1;
        }
        m[i] = t[i];
    }
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    for (int i = N-1; i >= 0; i--){
        if (b[i] && a[i] < m[i]){
            cout << 0 << endl;
            return 0;
        }
        if (i == N-1 || a[i] != a[i+1]){
            if (m[i] < a[i] || (b[i] && a[i] != m[i])){
                cout << 0 << endl;
                return 0;
            }
            b[i] = 1;
            m[i] = a[i];
        }
        m[i] = min(m[i], a[i]);
    }
    for (int i = 0; i < N-1; i++){
        if (b[i]) continue;
        ans *= m[i];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
} 


Measured memory_bytes: 2944
n=int(input())
b=list(map(int,input().split()))
ans=[]
count=0
while len(b)>0:
  count+=1
  for i in range(len(b),0,-1):
    if b[i-1]==i:
      ans.append(b.pop(i-1))
      break
  if count==101:
    print(-1)
    exit()
ans.reverse()
for i in range(n):
  print(ans[i])

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc128/tasks/abc128_a
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int apples, pieces;
    cin >> apples >> pieces;
    int total_pieces = (3 * apples) + pieces;
    cout << total_pieces / 2 << endl;
    return 0;
}

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


int main(){
  ll H,N;
  ll sum = 0;
  cin >> H >> N;
  rep(i,N){
    ll A;
    cin >> A;
    sum += A;
  }

  if(sum >= H)cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int main()
{
	LL a, b;

	scanf("%lld %lld", &a, &b);
	LL ans = 1000000000;
	ans *= ans;

	if (b >= a) ans = MIN(ans, b - a);
	if (b >= -a) ans = MIN(ans, 1 + b + a);
	if (-b >= a) ans = MIN(ans, 1 + -b - a);
	if (-b >= -a) ans = MIN(ans, 2 + -b + a);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
inline ll read(){
	ll res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100007;
int n,k,f[N],h[N];
signed main(){
	n=read(),k=read();
	for(int i=1;i<=n;i++) h[i]=read();
	for(int i=2;i<=n;++i){
        f[i]=0x3f3f3f3f;
        for(int j = 1;j<=k;++j){
            if(i-j<1) break;
            f[i] = min(f[i],f[i-j]+abs(h[i]-h[i-j]));
        }
    }
	cout<<f[n];
}


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

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

ll dp[301][90001];
ll dp2[301][90001];

ll modexp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    ll res = (x%m + m) % m; 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll mod = 998244353;
    ll n;
    cin >> n;

    ll a[n];
    ll sum = 0;

    rep(i,n)
    {
    	cin >> a[i];
    	sum = sum + a[i];
    }

    sort(a, a+n);

    ll ans1 = modexp(3,n,mod);

    dp[0][0] = modexp(2,n,mod);

    // cout << dp[0][0] << endl;
    dp2[0][0] = 1;

    fr(i,1,n)
    {
    	fr(j,0,sum)
    	{
    		dp[i][j] += dp[i-1][j];
    		dp2[i][j] += dp2[i-1][j];
    		dp[i][j] %= mod;
    		dp2[i][j] %= mod;

    		if(j-a[i-1]>=0)
    		{
    			ll x = modInverse(2,mod);
    			
    			x = x*(dp[i-1][j-a[i-1]]);
    			x = x%mod;

    			dp[i][j] = dp[i][j] + x;
    			dp[i][j] = dp[i][j]%mod;
    			dp2[i][j] = dp2[i][j] + (dp2[i-1][j-a[i-1]]);
    			dp2[i][j] = dp2[i][j]%mod;
    		}

    		// cout << i << " " << j << " " << dp[i][j] << endl;
    	}
    }

    // cout << dp[1][1] << endl;

    ll ans2 = 0;

    fr(i,0,sum)
    {
    	if(i+i>sum)
    	{
    		ans2 = ans2 + 3*dp[n][i];
    		// cout << dp[n][i] << " " << i << endl;
    		ans2 = ans2%mod;
    	}
    	else if(i+i==sum)
    	{
    		// cout << dp[n][i] << endl;
    		ans2 = ans2 + (3*dp[n][i]);
    		ans2 = ans2%mod;
    	}
    }

    // cout << dp2[n][sum/2] << endl;

    if(sum%2==0)
    	ans2 = ans2 - (3*dp2[n][sum/2]);
    ans2 = ans2 + mod;
    ans2 = ans2 %mod;
    // cout << ans2 << endl;
    ll ans = ans1 - ans2 + mod;
    ans = ans%mod;

    cout << ans << endl;
}


Measured memory_bytes: 422912
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep(i,n-2){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       ll n,ans=0;
       cin>>n;
       if(n>=400&&n<=599)
        ans=8;
       else if(n>=600&&n<=799)
        ans=7;
       else if(n>=800&&n<=999)
        ans=6;
       else if(n>=1000&&n<=1199)
        ans=5;
       else if(n>=1200&&n<=1399)
        ans=4;
       else if(n>=1400&&n<=1599)
        ans=3;
       else if(n>=1600&&n<=1799)
        ans=2;      
       else
        ans=1;
       cout<<ans;  
   }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll mod = 1e9 + 7;
#define EPS 1e-1
#define PI 3.14159265

#define iofile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;

ll fastpow(ll base, ll pow)
{
    if (!base)
        return 0;
    if (!pow)
        return 1;
    if (pow == 1)
        return base;
    ll x = fastpow(base, pow / 2) % mod;
    x *= x;
    x %= mod;
    if (pow % 2)
        x *= base;
    return x % mod;
}

ll inverse(ll x)
{
    return fastpow(x, mod - 2) % mod;
}

ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];
void init()
{
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= 1e6; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = inverse(fact[i]);
    }
}

void factorize(ll x, map<int, int> &ss)
{
    while (x % 2 == 0)
        ss[2]++, x /= 2;
    for (int i = 3; i <= sqrt(x); i += 2)
        while (x % i == 0)
            ss[i]++, x/= i;
    if (x > 2)
        ss[x]++;
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int arr[(int)1e5 + 5];
int dp[(int)1e5 + 5];
int n, k;

ll solve(int idx)
{
    if (idx >= n - 1)
        return 0;
    if (dp[idx] != -1)
        return dp[idx];
    ll res = 1e9;
    for (int i = idx + 1; i <= min(n - 1, idx + k); i++)
        res = min(res, abs(arr[idx] - arr[i]) + solve(i));
    return dp[idx] = res;
}

int main()
{
    fastio
    memset(dp, -1, sizeof dp);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

//?´????WA

long long cumsum[100010];

#define MOD 100000

int main() {
	long long n, m, s, a;

	cin >> n >> m;
	for (int i = 1; i < n; ++i) {
		cin >> s;
		cumsum[i] = (cumsum[i - 1] + s) % MOD;
	}

	long long pos = 0, ans = 0;
	while (m--) {
		cin >> a;
		ans += (cumsum[max(pos, pos + a)] - cumsum[min(pos, pos + a)]) % MOD;
		pos += a;
	}

	cout << ans % MOD << endl;

	return 0;
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  int n, m;
  cin >> n >> m;
  vector<int> x(m), y(m);
  rep(i, m) {
    cin >> x[i] >> y[i];
    x[i]--, y[i]--;
  }

  vector<int> cnt(n, 1);
  set<int> s;
  s.insert(0);
  rep(i, m) {
    if (s.find(x[i]) != s.end()) {
      s.insert(y[i]);
      if (cnt[x[i]] == 1) s.erase(x[i]);
    }
    cnt[x[i]]--, cnt[y[i]]++;
  }
  cout << s.size() << '\n';





  
  return 0;
}

Measured memory_bytes: 6144
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]
p = "+"
m = "-"
for i in range(2**3):
    ans = ""
    check = int(n[0])
    for j in range(3):
        ans += n[j]
        if ((i >> j) & 1):
            ans += p
            check += int(n[j+1])
        else:
            ans += m
            check -= int(n[j+1])
    ans += n[3]
    if check == 7:
        ans += "=7"
        print(ans)
        exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  vector<int> snukes(n+1, 0);
  for (int i=0;i<k;i++) {
    int d, t;
    cin>>d;
    for (int j=0;j<d;j++) {
      cin>>t;
      snukes[t]++;
    }
  }
  int ctr = 0;
  for (auto& s : snukes) {
    ctr += (s>0) ? 0 : 1;
  }
  cout<<ctr-1<<endl;
  return 0;
}

Measured memory_bytes: 3624
object Main extends App{
  val n: Int = io.StdIn.readInt
  val heap: Array[String] = io.StdIn.readLine().split(" ")

  for (i <- heap.indices) {
    val sb: StringBuilder = new StringBuilder
    val li: Int = i*2+1
    val ri: Int = i*2+2

    sb.append(s"node ${i+1}: key = ${heap(i)}, ")
    if (i != 0) {
      val pi: Int = (i-1)/2
      sb.append(s"parent key = ${heap(pi)}, ")
    }
    if (li < heap.length) {
      sb.append(s"left key = ${heap(li)}, ")
      if (ri < heap.length) sb.append(s"right key = ${heap(ri)}, ")
    }
    println(sb.result)
  }
}


Measured memory_bytes: 44128
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
unordered_map<int,int> um;
unordered_set<int> us;
set<int> s;
// v.front() gives the first element of vector 
// v.back()  gives the last element of vector
// insert erase substr
//g++ -o Legendary-Grandmaster Legendary-Grandmaster.cpp&Legendary-Grandmaster.exe 
//cd C:\Users\158si\Desktop\Algorithim\codeForces\elite
// for-bash cd C:/Users/158si/Desktop/Algorithim/codeForces/elite

int main(){
	long long n;
	cin >> n;
	long long cnt=0;
	int i = 0;
	//int val = 1;
	while(n>0){
	    cnt += pow(2,i);
		n/=2;
		i++;
	}
	cout << cnt;
	return 0;
}

























Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>

using namespace std;

typedef unsigned uint;
typedef long long Int;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }

int fr[550][550], invite[550];
int main()
{
	int n, m;
	while (cin >> n >> m, n && m){
		memset(fr, 0, sizeof(fr));
		memset(invite, 0, sizeof(invite));
		int a, b;
		for (int i = 0; i < m; i++){
			cin >> a >> b;
			fr[a][b] = 1;
			fr[b][a] = 1;
		}
		vector <int> myfr;
		for (int i = 1; i <= n; i++){
			if (fr[1][i]){
				// 1テ」ツ?ィiテ」ツ?古・ツ渉凝ゥツ??
				invite[i] = 1;
				myfr.push_back(i);
			}
		}
		// テ」ツ?ィテ」ツつづ」ツ??」ツ?。テ」ツ?ョテ」ツ?ィテ」ツつづ」ツ??」ツ?。テ」ツつ津」ツ?陛」ツ?古」ツ??
		for (int i = 0; i < myfr.size(); i++){
			for (int j = 1; j <= n; j++){
				if (fr[myfr[i]][j]){
					invite[j] = 1;
				}
			}
		}

		int ret = 0;
		for (int i = 2; i <= n; i++){
			if (invite[i]){
				ret++;
				// cout << i << " ";
			}
		}
		// puts("");
		cout << ret << endl;
	}

    return 0;
}

Measured memory_bytes: 2408
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
vector<ll> g[ohara];
ll vi[ohara];
unordered_map<ll,ll> used;
ll ha[ohara];
ll ha_cou=0;
ll dp[ohara];
vector<ll> gyaku[ohara];

//-------------------------↓↓↓↓↓↓------------------------

ll dfs(ll parent,ll now){
    ll depth=0;
    rep(i,Size(g[now])){
        depth=max(dfs(now,g[now][i]),depth);
    }
    //cerr<<now+1<<" "<<depth<<"\n";
    if(depth==k-1){
        if(parent!=0)ans++;
        return 0;
    }
    else return depth+1;
}

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

    cin>>n>>k;
    rep(i,n)cin>>a[i];
    if(a[0]!=1)ans=1;
    rrep(i,1,n){
        if(a[i]-1==i)continue;
         g[a[i]-1].push_back(i);
         gyaku[i].push_back(a[i]-1);
    }
    dfs(0LL,0LL);
    Cout(ans);
    return 0;
}


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

int n,q;

int main(){
    cin >> n >> q;
    queue<string> qs;
    queue<int> qi;
    queue<string> res_s;
    queue<int> res_i;
    int now=0;

    for(int i=0;i<n;i++){
        string s;
        int a;
        cin >> s >> a;
        qs.push(s);
        qi.push(a);
    }

    while(qs.size()>=1){
        string s=qs.front();
        int i=qi.front();

        if(i<=q){
            now += i;
            res_s.push(s);
            qs.pop();
            res_i.push(now);
            qi.pop();
        }else{
            qs.pop();
            qi.pop();
            qs.push(s);
            qi.push(i-q);
            now += q;
        }
    }

    for(int i=0;i<n;i++){
        string s=res_s.front();
        int a=res_i.front();
        res_s.pop();
        res_i.pop();
        cout <<s<<" "<<a<<endl;
    }
}


Measured memory_bytes: 5696