akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,m;
double ans=INF,dp[610];
vector<int>v[610];
double func(int b){
    dp[n]=0;
    for(int i=n-1;i>=1;i--){
        double sum=0,ma=0;
        int num=v[i].size();
        for(int to:v[i]){
            sum+=dp[to];
            chmax(ma,dp[to]);
        }
        if(i==b&&num>=2){
            num--;
            sum-=ma;
        }
        dp[i]=sum/num+1;
    }
    return dp[1];
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    rep(i,m){
        int s,t;
        cin>>s>>t;
        v[s].pb(t);
    }
    rep(i,n)chmin(ans,func(i));
    printf("%.12lf\n",ans);
	return 0;
}


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

int arr[5];

void findTasty(){
    int a = arr[0];
    int b = arr[1];
    int c = arr[2]; 

    int count = 0; 
    int antidote = a + b + 1; 
    int poisonous = c; 

    if(antidote  >= poisonous){
      count = count + poisonous; 
      count = count + b; 
    }
    else{
      count = count + antidote; // Num poisonous
      count = count + b;
    }

    // Since tasty cookies are finished
    cout << count << endl;
}

int main(){
    for(int i = 0; i < 3; i++){
        cin >> arr[i];
    }
    findTasty();
}

Measured memory_bytes: 256
k=int(input())
a,b=list(map(int,input().split()))


if a%k==0 or b%k==0:
    print("OK")
elif b//k-a//k>=1:
    print("OK")
elif b/k-a/k<1 and a%k>b%k:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
using vi=vector<int>;  using vs=vector<string>; using gi=greater<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define soao(c) sort((c).begin(),(c).end()) //昇順
#define sodo(c) sort((c).begin(),(c).end(),gi()) //降順
#define rev(c) reverse((c).begin(), (c).end())



int main(){
	int a,b; cin>>a>>b;
	if(a%2==0||b%2==0) cout<<"Even"<<endl;
	else cout<<"Odd"<<endl;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;

int main() {
  ll n, a, b, c, d;

  cin >> n >> a >> b >> c >> d;

  if (a > b) swap(a, b);
  b = b - a;
  a = 0;
  n--;

  rep (i, n + 1) {
    ll s, t;

    if ((n - i) % 2) {
      s = i + 1;
      t = (n - i - 1) / 2;
    } else {
      s = i;
      t = (n - i) / 2;
    }

    ll p = c * s + (c - d) * t;
    ll q = d * s + (d - c) * t;

    if (p <= b && b <= q) {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
typedef std::pair<ll, ll> P;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int main(){


  int N, K;
  cin >> N >> K;

  int ans=0;

  int hen=(N-1)*(N-2)/2-K;

  if (hen<0){
    ans=-1;
    cout << ans <<endl;
  }
  else{
    ans=N*(N-1)/2-K;
    cout << ans <<endl;

  reps(i,1,N)
    reps(j,i+1,N+1){
    cout << i << " " << j <<endl;
      if(--ans<=0)
    {
      i=N;
      j=N+1;
    }
   }
  }

  return 0;
}


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

void swap(int &p, int &q)
{
    int x;
    if (p > q)
    {
        x = p;
        p = q;
        q = x;
    }
}

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);

    swap(a, b);
    swap(b, c);
    swap(a, b);

    printf("%d %d %d\n", a, b, c);
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int extgcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  int g = extgcd(b, a % b, y, x);
  y -= (a / b) * x;
  return g;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a, b, d;
  while (cin >> a >> b >> d, a) {
    int x, y;
    int g = extgcd(a, b, x, y);
    a /= g, b /= g, d /= g;
    x *= d, y *= d;

    int ax = x, ay = y;
    int p, q;
    int w1 = abs(x) + abs(y), w2 = a * abs(x) + b * abs(y);
    p = x, q = y;
    while (true) {
      p -= b, q += a;
      if (abs(p) + abs(q) <= w1) {
        if (abs(p) + abs(q) == w1) {
          if (a * abs(p) + b * abs(q) < w2) {
            w2 = a * abs(p) + b * abs(q);
            ax = p, ay = q;
          }
        } else {
          w1 = abs(p) + abs(q);
          w2 = a * abs(p) + b * abs(q);
          ax = p, ay = q;
        }
      } else break;
    }
    p = x, q = y;
    while (true) {
      p += b, q -= a;
      if (abs(p) + abs(q) <= w1) {
        if (abs(p) + abs(q) == w1) {
          if (a * abs(p) + b * abs(q) < w2) {
            w2 = a * abs(p) + b * abs(q);
            ax = p, ay = q;
          }
        } else {
          w1 = abs(p) + abs(q);
          w2 = a * abs(p) + b * abs(q);
          ax = p, ay = q;
        }
      } else break;
    }
    cout << abs(ax) << " " << abs(ay) << endl;
  }

  return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1005;
const int MOD=1e9+7;
const int dx[] = {1, 0} ;
const int dy[] = {0, 1} ;
queue<pair<int,int> >q;
char s[N][N];
ll dp[N][N];
bool vis[N][N] ;
int n,m;
signed main(){
	scanf("%d%d", &n, &m) ;
	for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1) ;
	q.push(make_pair(1, 1)) ; dp[1][1] = 1 ; vis[1][1] = 1 ;
	while (!q.empty()) {
		pair<int,int> now = q.front() ; q.pop() ;
		for (int i = 0; i < 2; i++) {
			int tx = now.first + dx[i], ty = now.second + dy[i] ;
			if (s[tx][ty] == '.') {
				dp[tx][ty] = (dp[tx][ty] + dp[now.first][now.second]) % MOD ;
				if (!vis[tx][ty]) q.push(make_pair(tx, ty)), vis[tx][ty] = 1 ;
			}
		}
	}
	printf("%lld\n", dp[n][m]) ;
	return 0 ;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  long a, b, c=1, d=0, e, f, g, h, m, n;
  cin >> n >> a >> b;
  e=max(a, b)-(n+min(a, b));
  if(e<=0) co(0);
  else co(e);
    
  return 0;
}


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

int main() {
	int d;
	cin >> d;
	const int n = 26;
	vector<int> c(n);
	vector<vector<int>> s(d, vector<int>(n));
	rep(i, n) cin >> c[i];
	rep(i, d) rep(j, n) cin >> s[i][j];
	vector<int> t(d), last(n);
	// rep(i, d) {
	// 	cin >> t[i];
	// 	t[i]--;
	// }
	
	ll ans = 0;
	rep(i, d) {
		ll mx = -1;
		int now = 0;
		rep(j, n) {
			if(mx < s[i][j]) {
				mx = s[i][j];
				now = j;
			}
		}
		cout << now+1 << endl;
		ans += s[i][now];
		last[now] = i+1;
		rep(j, n) {
			ans -= c[j] * (i+1-last[j]);
		}
	}
	
	
	return 0;
}

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

int N, M, Q, a[55], b[55], c[55], d[55], A[12];
int maxScore;

void generate(int idx) {
    if (idx == N + 1) {
        int score = 0;
        for (int i = 1; i <= Q; i++) {
            if (A[b[i]] - A[a[i]] == c[i])
                score += d[i];
        }

        maxScore = max(maxScore, score);
        return;
    }

    for (int num = A[idx - 1]; num <= M; num++) {
        A[idx] = num;
        generate(idx + 1);
    }
}

int main() {
    cin >> N >> M >> Q;
    for (int i = 1; i <= Q; i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];

    maxScore = 0;

    A[0] = 1;
    generate(1);

    cout << maxScore << endl;
}


Measured memory_bytes: 3536
// 解説動画を見て理解
// K個の部屋を移動する操作をA、K個の部屋をアンロックする操作をBと呼ぶ
// A -> B -> A -> B -> ... と操作を繰り返すわけだが、
// 最初のAを除くと、B -> Aの繰り返しとみなせる
// Bで、もっとも近い出口までの壁をK個壊せば、Aはその方向に確実にK回進めるので、
// 壁はないのと同じになる


#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

using P = pair<int,int>;

int H, W, K;
vector<string> cells;
vector<vector<int>> reach;
const int MAX = 10000;

bool within_board(int w, int h) {
	return (0 <= w && w < W && 0 <= h && h < H);
}

void debug_print_reach(){
    cout << endl;
    REP(h,H) {
        REP(w,W) {
            cout << reach[h][w] << "\t";
        }
        cout << endl;
    }
    cout << endl;
}

int dh[4] = { 1, -1, 0, 0 };
int dw[4] = { 0, 0, 1, -1 };
void fill_room(P start, int turn) {
	set<P> poses{ start };
	REP(k, K) {
		set<P> new_poses;
        for (auto& pos: poses) {
            auto w = pos.first;
            auto h = pos.second;
            REP(d, 4) {
                auto w2 = w + dw[d];
                auto h2 = h + dh[d];
				if (within_board(w2, h2)
                    && cells[h2][w2] != '#'
                    && reach[h2][w2] > k) {
                    new_poses.insert(P(w2,h2));
                    reach[h2][w2] = k;
                }
            }
        }
        poses = new_poses;
    }
}

int main(void)
{
    cin.sync_with_stdio(false);
    cin >> H >> W >> K;
    cells.resize(H);
    reach.resize(H);
	P start;
    REP(h,H) {
        cin >> cells[h];
        reach[h].resize(W, MAX);
        auto loc = cells[h].find('S');
        if (loc != string::npos) {
            start = mp(loc, h);
            reach[h][loc] = 0;
            cells[h][loc] = '.';
        }
    }

	fill_room(start, 0);
    // debug_print_reach();

    int min_dist = 1e9;
    REP(h,H) {
        REP(w,W) {
            if (reach[h][w] < MAX) {
                auto dist = min(w, min(h, min(W-1-w, H-1-h)));
                min_dist = min(min_dist, dist);
            }
        }
    }


    cout << ((min_dist + K - 1) / K) + 1 << endl;
    return 0;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> s(n+1, 0);
  rep2(i, 1, n+1){
    for(int j = i; j <= n; j += i){
      s.at(j)++;
    }
  }
  ll ans = 0;
  rep2(i, 1, n+1) ans += (ll)i * s.at(i);
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        int l, r;
        cin >> l >> r;
        ans += (r - l) + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
void sor(vel &v) { sort(v.begin(), v.end()); }
int zero() { return 0; }
signed main() {
	int h, w;
	cin >> h >> w;
	vvel a(h, vel(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	int ma1 = 10000 * h*w*(h + w) + 1;
	vvel dp(h, vel(w,ma1));
	dp[0][0] = 0;
	for (int i = 0; i <= h * w; i++) {
		vvel ndp = dp;
		for (int j = 0; j < h; j++) {
			for (int k = 0; k < w; k++) {
				int mj = j; int mk = k;
				mj--;
				if (mj >= 0 and mj<h and mk<w and mk >= 0) {
					mmin(ndp[mj][mk], dp[j][k] + i*2*a[mj][mk] + a[mj][mk]);
				}
				mj += 2;
				if (mj >= 0 and mj < h and mk < w and mk >= 0) {
					mmin(ndp[mj][mk], dp[j][k] + i * 2 * a[mj][mk] + a[mj][mk]);
				}
				mj--;
				mk++;
				if (mj >= 0 and mj < h and mk < w and mk >= 0) {
					mmin(ndp[mj][mk], dp[j][k] + i * 2 * a[mj][mk] + a[mj][mk]);
				}
				mk -= 2;
				if (mj >= 0 and mj < h and mk < w and mk >= 0) {
					mmin(ndp[mj][mk], dp[j][k] + i * 2 * a[mj][mk] + a[mj][mk]);
				}
			}
		}
		dp = ndp;
	}
	cout << dp[h - 1][w - 1] << endl;
	return 0;
}



Measured memory_bytes: 3196
import numpy as np

N, M = map(int,input().split())

taste_list = []
for i in range(N):
  taste_i = M + (i+1) - 1
  taste_list.append(taste_i)
  
taste_list = np.array(taste_list)

if M >= 0:
	ind = np.argmin(taste_list)
else:
  if N - 1 >= M * -1:
    ind = M * -1
  else:
    ind = N -1
    

taste_n1 = 0
for i in range(N):
  if i != ind:
  	taste_n1 += M + (i+1) -1
    
print(taste_n1)


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

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

int main(){
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++) cin>>arr[i];

	int ans = arr[0];
	for(int i = 0; i < n; i++){
		ans = gd(ans,arr[i]);
	}
	cout<<ans;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cstddef>
#include <cinttypes>
#include <memory>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <array>
#include <valarray>
#include <string>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <queue>
#include <complex>
#include <tuple>
#include <utility>
#include <functional>
#include <algorithm>
#include <numeric>

using namespace std;

const double EPS = 1e-10;
const int64_t INF = 1e9;

typedef long long ll;

const ll MOD = 1000000007;

int main()
{
	int N;

	scanf("%d", &N);

	vector<ll> se(N), nw(N);
	for (int i = 0; i < N; ++i) {
		ll x, y;
		scanf("%lld%lld", &x, &y);
		se[i] = x + y;
		nw[i] = x - y;
	}

	sort(se.begin(), se.end());
	sort(nw.begin(), nw.end());

	printf("%lld\n", max(se[N-1]-se[0], nw[N-1]-nw[0]));

	return 0;
}



Measured memory_bytes: 6044
import java.math.BigInteger;
import java.util.Scanner;

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

		for(int i = 0;i<n;i++){
			String inputBigInt1 = stdIn.next();
			String inputBigInt2 = stdIn.next();
			if(inputBigInt1.length() > 80 | inputBigInt2.length() > 80){
				System.out.println("overflow");
				continue;
			}
			BigInteger bigInt1 = new BigInteger(inputBigInt1);
			BigInteger bigInt2 = new BigInteger(inputBigInt2);
			BigInteger sumBigInt = bigInt1.add(bigInt2);
			if(sumBigInt.toString().length() > 80){
				System.out.println("overflow");
				continue;
			}
			System.out.println(sumBigInt);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define N 1300

int main()
{
  int A, B;
  cin>>A>>B;

  for(int i=1; i<N; i++){
    double x, y;
    x=i*0.08;  y=i*0.1;
    if((int)x==A && (int)y==B){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<"-1"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n;
  
  scanf("%d",&n);
  
  int a[n];
  int i;
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  
  int two=1;
  for(i=1;i<=n;i++)
  {
    two=a[two-1];
    if(two==2)
    {
      printf("%d\n",i);
      return 0;
    }
  }
  if(two!=2)
  {
    printf("-1\n");
  }
  return 0;
}
  

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int N;

string binary_number(int a) // int型の10進数をstring型の2進数に変換
{
    string b = "";
    for (int i = 1; i <= N; i++)
    {
        char mod = a % 2 + '0';
        b = mod + b;
        a /= 2;
    }
    return b;
}

int main()
{
    cin >> N;
    int A[20], x[20][20];
    char y[20][20];
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
        for (int j = 1; j <= A[i]; j++)
        {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;
    for (int hu = 0; hu < pow(2, N); hu++) // honest or unkind
    {
        string hu2 = binary_number(hu);
        // ex. N == 15のとき、hu2 == "010001000111101"（15桁）

        bool success = true;
        for (int i = 1; i <= N; i++)
        {
            if (hu2[i - 1] == '1') // 今回、人iは正直者だが・・・
            {
                for (int j = 1; j <= A[i]; j++)
                {
                    if (hu2[x[i][j] - 1] != y[i][j]) // もし人iの証言が違ったら・・・
                    {
                        success = false; // ダメです
                    }
                }
            }
        }

        if (success == true)
        {
            int honest = 0;
            for (int i = 1; i <= N; i++)
            {
                if (hu2[i - 1] == '1') honest++;
            }
            ans = max(ans, honest);
        }
    }

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

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

int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int y=0;
  for(int i=0; i < A+1; i++){
    for(int j=0; j < B+1; j++){
      for(int k=0; k < C+1; k++){
        if(500*i+100*j+50*k==X) y++;
      }
    }
  }
  cout << y << endl;
}

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

typedef long long ll;
int main()
{
	string s;
	cin>>s;
	int f=0;
	for(int i=1;i<4;i++)
        if(s[i]==s[i-1])
            f=1;
        if(f)
            cout<<"Bad"<<endl;
        else
            cout<<"Good"<<endl;
	return 0;
}


Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    N = int(input())
    if N==1:
        print(0)
        exit()
    
    ret = factorization(N)
    ans = 0
    already = set()
    while len(ret) > 0:
        #print(ret)
        x = ret.pop()
        #print(x)
        e = 1
        while e <= x[1]:
            p = x[0]**e
            if not p in already:
                already.add(p)
                break
            e += 1
        else:
            continue
        y = [x[0], x[1]-e]
        ans += 1
        if y[1] > 1:
            ret.append(y)
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 63492
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ms(x, t) memset(x, t, sizeof(x))
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define mp make_pair
#define pb push_back
#define pf push_front
#define endl "\n"
typedef pair<int, int> pll;
typedef pair<int, pll> plll;
typedef vector<int> vl;
typedef vector<vector<int>> vvl;
typedef vector<pll> vpll;
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;

const int limit = 1e5 + 1;
const int inf = 1e7;
const int mod = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - i - 1]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else if (s[3] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    //cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int data[6];

void solve(string);

main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    for(int i=0;i<6;i++){
      data[i]=i+1;
    }
    int sum=1;
    for(int i=0;i<n;i++){
      string in;
      cin >> in;
      solve(in);
      sum+=data[0];
    }
    cout << sum << endl;
  }
  return 0;
}

void solve(string str){
  int tmp[6];
  for(int i=0;i<6;i++){
    tmp[i]=data[i];
  }
  if(str=="North"){
    data[0]=tmp[1];
    data[1]=tmp[5];
    data[2]=tmp[2];
    data[3]=tmp[3];
    data[4]=tmp[0];
    data[5]=tmp[4];
  }else if(str=="East"){
    data[0]=tmp[3];
    data[1]=tmp[1];
    data[2]=tmp[0];
    data[3]=tmp[5];
    data[4]=tmp[4];
    data[5]=tmp[2];
  }else if(str=="West"){
    data[0]=tmp[2];
    data[1]=tmp[1];
    data[2]=tmp[5];
    data[3]=tmp[0];
    data[4]=tmp[4];
    data[5]=tmp[3];
  }else if(str=="South"){
    data[0]=tmp[4];
    data[1]=tmp[0];
    data[2]=tmp[2];
    data[3]=tmp[3];
    data[4]=tmp[5];
    data[5]=tmp[1];
  }else if(str=="Right"){
    data[0]=tmp[0];
    data[1]=tmp[2];
    data[2]=tmp[4];
    data[3]=tmp[1];
    data[4]=tmp[3];
    data[5]=tmp[5];
  }else if(str=="Left"){
    data[0]=tmp[0];
    data[1]=tmp[3];
    data[2]=tmp[1];
    data[3]=tmp[4];
    data[4]=tmp[2];
    data[5]=tmp[5];
  }
}

Measured memory_bytes: 0
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define f0x(i, a, b) for (int i = (a); i < (b); i++)
#define fax(i, a) for (int i = 0; i < (a); i++)
#define faxd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define f0xd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll C[MX]; ll dp[MX]; map<ll, int> dpCnt; vl vals;
//dp[i] = sum of dp[C[i]] so far +

int main() {
    int N; cin >> N;
    fax(i,N){
      cin >> C[i];
    }
    fax(i,N-1){
   	if(C[i] == C[i+1]){
   		continue;
   	}
   	else{
   		vals.pb(C[i]);
   	}
   }
   vals.pb(C[N-1]);
   dp[0] = 1;
   dpCnt[C[0]] = 1;
   f0x(i,1,sz(vals)){
     dp[i] = dp[i-1] + dpCnt[vals[i]];
     dp[i] %= MOD;
     dpCnt[vals[i]] = dp[i];
   }
   cout << dp[sz(vals)-1]%MOD << "\n";
}


Measured memory_bytes: 17392
n,k = list(map(int, input().split()))
lst = [None for i in range(n)]

for i in range(n):
    a,b = list(map(int, input().split()))
    lst[i] = (a,b)

# print(lst)
lst.sort(key=lambda x:x[0])
# print(lst)

count = 0
for i in range(n):
    count += lst[i][1]
    if count>=k:
        print(lst[i][0])
        exit()


Measured memory_bytes: 18288
#include<iostream>

using namespace std;

const int MAX = 1000001;
bool data[MAX];
int n,a,b;


void solve(){
  data[a] = data[b] = true;

  for(int i = 1; i < MAX; i++){
    if(i-a>0) data[i] = (data[i] || data[i-a]);
    if(i-b>0) data[i] = (data[i] || data[i-b]);
  }

  int ans = 0;
  for(int i = 1; i <= n; i++)
    if(!data[i]) ans++;

  cout << ans << endl;
}

int main(){
  while(cin >> n >> a >> b && n+a+b){
    fill(data,data+MAX,false);
    solve();
    int x = 100, y = 200;
    x = max(x,y);
  }
  return 0;
}

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

int64_t nx(int64_t n){
  int64_t x_ans = 1;
  for(int i=1; i<=n; i++){
    x_ans *= i;
    x_ans %= 1000000007;
  }
  return x_ans;
}

int main(){
  int N,M;
  cin >> N >> M;
  if(N-M == 1 || M-N == 1){
    cout << nx(N) * nx(M) %1000000007 << endl;
  }
  else if(N == M){
    cout << nx(N) * nx(M) * 2 %1000000007 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

//最初に自分は"a"と出力する
//その後、aで終わる単語を出力し続ける
//相手はaaからazの26通りしかなくなる
//相手がaXと言ってきたら、こちらは"Xaa"と返せばよい
//"Xa"としないのは、"aa"に対して"aa"と返してしまうからである

bool judge(signed char word[3]);

int main()
{
    signed char word[3] = {};
    printf("?a\n");
    while (1) {
        fflush(stdout);
        scanf("%s", word);
        if (judge(word)) {
            printf("?%caa\n", word[1]);
        } else {
            printf("!OUT\n");
            break;
        }
    }
    return 0;
}


bool judge(signed char word[3])
{
    static bool char_used [256] = {};
    char_used[0] = true;
    if (word[0] != 'a' ) { return false;  }
    if (char_used[word[1]]) { return false; }
    char_used[word[1]] = true;
    return true;
}

Measured memory_bytes: 1256
A, B = map(int,input().split())

ans = 0
count = 0
for i in range(2):
    count = max(A,B)
    if A == B:
        A -= 1
    elif A == count and A!= B:
        A -= 1
    elif B == count and A != B:
        B -= 1
    ans += count

print(ans)

Measured memory_bytes: 3060
import numpy as np

N,M,C = map(int, input().split())
B = np.array(input().split(), dtype=float)

A = np.zeros((N,M))
for i in range(N):
    A[i,:] = np.array(input().split(), dtype=float)

print(np.sum((np.dot(A,B)+C > 0)))

Measured memory_bytes: 14428
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(long long N){
  cout << (N % 2 != 0 ? (double)(N / 2 + 1) / N : 0.5000000000) << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  solve(N);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#include<cstdio>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<string>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include<set>
#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)
#define INF9                1000000010
#define INF18               1000000000000000010
#define dist(ax,ay,bx,by)   sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
#define gcd(a,b)            __gcd(a,b)
#define lcm(a,b)            (a*b)/__gcd(a,b)
#define m_p(a,b)            make_pair(a,b)
#define sqr(a)              ((a)*(a))
#define pb                  push_back
#define bpll(a)             __builtin_popcountll(a)
#define MX                  1000000
#define PI                  acos(-1)
#define mod                  1000000007
#define cnt_bin(n)          __builtin_clzll(0ll) - __builtin_clzll(n)

typedef long long lli;
using namespace std;

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

    lli cnt=0;
    lli ans=0;

    for(lli i=0; i<3; i++)
    {
        if(str[i]=='R') cnt++;
        else
        {
            ans= max(ans, cnt);
            cnt=0;
        }
    }

    ans= max(ans, cnt);
    cout<<ans<<endl;

    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n-1); 0=<i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

int main(void){
    ll H1,M1,H2,M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    ll H_sa = 0;
    ll M_sa = 0;

    H_sa = H2 - H1;
    M_sa = M2 - M1; //負になるケースがある

    ll time = (H_sa*60) + M_sa;

    cout << (time-K) << endl;

    return 0;
}

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

using namespace std;

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

    double ans = 0.0;
    for (long long x = 1; x <= N; ++x) {
        double tmp = 1.0;
        long long y = x;
        while (y < K) {
            y *= 2;
            tmp /= 2.0;
        }
        ans += tmp;
    }

    ans /= N;
    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void){
    char str[5];
    int i,a;
    a=0;
    scanf("%s",str);
    for (i=0;i<4;i++){
        if (str[i]=='A' && str[i+1]=='C'){
            a=a+1;
        }
        else{
        }
    }
    if (a>0){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, q;
vector<int> cost;

void dfs(int v, int p, vector<vector<int>> &G){
	if(p != -1) cost[v] += cost[p];
	for(auto nv : G[v]){
		if(nv == p) continue;
		dfs(nv, v, G);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> q;
	cost.resize(n, 0);
	vector<vector<int>> G(n);
	int a, b;
	rep(i,n-1){
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int p, x;
	rep(i,q){
		cin >> p >> x;
		cost[p-1] += x;
	}
	dfs(0, -1, G);
	rep(i,n-1) cout << cost[i] << " ";
	cout << cost[n-1] << endl;
	return 0;
}

Measured memory_bytes: 23552
function Main(input){
    const S = input.split("\n")[0];
    const dfs = (t, i) => {
        if(i==S.length-1)
            return t.split("+").map(Number).reduce((a,b) => Number(a)+Number(b));
        return  dfs(t+S[i+1], i+1) + dfs(t+"+"+S[i+1], i+1);
    }
    return console.log(dfs(S[0],0));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29768
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int v[10];
    for (int i=0; i<10; ++i) {
        cin >> v[i];
    }
    sort(v, v + 10);
    cout << v[9] << endl << v[8] << endl << v[7] << endl;
    return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}

int main() {
	int n;
	cin >> n;
	vector<ll> a(n*3);
	priority_queue<ll, vector<ll>, greater<ll>> pq1;
	priority_queue<ll, vector<ll>, less<ll>> pq2;
	priority_queue<ll, vector<ll>, greater<ll>> Pq1;
	priority_queue<ll, vector<ll>, less<ll>> Pq2;
	ll be = 0;
	ll af = 0;
	rep(i, 3 * n) {
		cin >> a[i];
		if (i < n) {
			Pq1.push(a[i]);
			be += a[i];
		}
		if (i >=2* n) {
			Pq2.push(a[i]);
			af += a[i];
		}
	}
	/*if (n == 1) {
		cout << max(a[0] - a[1], max(a[1] - a[2], a[0] - a[2]));
		return 0;
	}*/
	ll max = LLONG_MIN;
	pq1 = Pq1;
	pq2 = Pq2;
	ll B = be;
	//cout << af << " " << B << endl;
	vector<ll> sum1(n+1);
	vector<ll> sum2(n+1);
	ll  A = af;
	sum1[0] = be;
	sum2[n] = af;
	for (int i = n; i < 2 * n; i++){
		
		
		ll x;
		x = pq1.top();
		//cout << "�O��"<<x << endl;
		//cout << x << " " << a[i] << endl;
		if (x<a[i]) {
			B += a[i] - x;
			pq1.pop();

			pq1.push(a[i]);
		}
		sum1[i-n+1] = B;
		x = pq2.top();
		//cout << x << " " << a[3*n-1-i] << endl;
		if (x > a[3*n-1-i]) {
			A += a[3*n-1-i] - x;
			pq2.pop();

			pq2.push(a[3*n-1-i]);
		}
		sum2[n-(i - n)-1] = A;
		//cout << A << " " << B << endl;
		//Pq1 = pq1;
		//if (max < B-A)max = B-A;
	}
	rep(i, n+1) {
		if (max < sum1[i] - sum2[i])max = sum1[i] - sum2[i];
		//cout << sum1[i] << " " << sum2[i] << endl;
	}

	cout << max<< endl;
}


Measured memory_bytes: 9856
program abc106b
      implicit none
      integer::n
      integer::i,j,count,ans
      
         read *, n
         
         ans=0
         do i=1,n,2
            count=0
            do j=1,n
               if (mod(i,j)==0) count=count+1
            end do
            if (count==8) ans=ans+1
         end do
         
         print *, ans
         
   end program abc106b

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; void solve(); int main(){cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); solve();}
using ll=int_fast64_t; using ld=long double; using pll=pair<ll,ll>; using pld=pair<ld,ld>;
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}

void solve(){
  ll n,m; cin>>n>>m;
  const ll inf=1<<30;
  auto A=make_v(n,n,inf);
  rep(_,m){
    ll a,b; cin>>a>>b;
    --a; --b;
    A[a][b]=1;
  }

  // Warshall-Floyd
  auto B=A;
  rep(k,n)rep(i,n)rep(j,n){
    B[i][j]=min(B[i][j],B[i][k]+B[k][j]);
  }

  // output
  ll len=inf;
  ll index=-1;
  rep(i,n){
    if(len>B[i][i]){
      len=B[i][i];
      index=i;
    }
  }
  if(len==inf){
    cout<<-1<<"\n";
    return;
  }

  // path restoration
  ll u,v;
  u=v=index;
  vector<ll> path{u};
  while(B[u][v]!=A[u][v]){
    rep(w,n){
      if(B[u][v]==A[u][w]+B[w][v]){
        u=w;
        path.push_back(w);
        break;
      }
    }
  }
  cout<<path.size()<<"\n";
  for(ll v:path) cout<<v+1<<"\n";
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
LL sum(LL a, LL b){
    LL cnt=0;
    cnt=(b-a+1)*(a+b)/2;
    return cnt;
}
int main(){
    int n, m;
    cin >> n >> m;
    vector<LL> h(n);
    vector<bool> cnt(n,true);
    LL ans = 0;
    REP(i,n){
        cin >> h[i];
    }
    REP(i,m){
        LL a,b;
        cin >> a >> b;
        a--;
        b--;
        if(h[a]>h[b]) cnt[b]=false;
        else if(h[a]<h[b]) cnt[a]=false;
        else{
            cnt[a]=false;
            cnt[b]=false;
        }
    }
    REP(i,n){
        if(cnt[i]==true) ans++;
        
    }
    cout << ans << endl;

}
    




Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=998244353;

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;i++)cin>>ar[i];
    int br[n]={0};
    for(int i=n-2;i>-1;i--){
        if(ar[i]>=ar[i+1])br[i]=br[i+1]+1;
        else br[i]=0;
    }
    int ma=0;
    for(int i=0;i<n;i++)ma=max(ma,br[i]);
    cout<<ma;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
#define range(i,a,n) for(int i=a;i<n;i++)
#define rep(i,n) range(i,0,n)
#define all(a) a.begin(),a.end()

int main(){
	int n,d,x; cin>>n>>d>>x;
	vvi v(d,vi(n));
	for(auto&l:v)for(auto&i:l)cin>>i;
	rep(k,d-1){
		vi dp(x+1);
		iota(all(dp),0);
		rep(i,n)range(j,v[k][i],x+1){
			dp[j]=max(dp[j], dp[j-v[k][i]]+v[k+1][i]);
		}
		x=max(0,*max_element(all(dp)));
	}
	cout<<x<<endl;
	return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <math.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n1,n2) for(int i=n1;i<n2;i++)
using namespace std;
typedef long long ll;

int main() {
    int c[3][3];
    REP(i,3){
        REP(j,3){
            cin >> c[i][j];
        }
    }
    bool flag = true;
    REP(i,2){
        REP(j,2){
            if(c[i][j]+c[i+1][j+1]!=c[i+1][j]+c[i][j+1]){
                flag = false;
            }
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}




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

Xmax = -2*10**9
Ymax = -2*10**9
Xmin = 2*10**9
Ymin = 2*10**9


for i in range(N):
    x, y = map(int, input().split())
    if (x + y >= Xmax):
        Xmax = x + y
    if (x + y <= Xmin):
        Xmin = x + y
    if (x - y >= Ymax):
        Ymax = x - y
    if (x - y <= Ymin):
        Ymin = x - y

print(max(Xmax - Xmin, Ymax - Ymin))

Measured memory_bytes: 9216
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
const ll INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

ll N;
ll W;
vii a;
ll memo[105][100050];


ll dp(ll at, ll v){
    if (memo[at][v] != -1) return memo[at][v];
    if (v == 0) return 0;
    if (at > N - 1) return W + 1;
    ll mn = dp(at + 1, v);
    if (v >= a[at].second) mn = min(mn, dp(at + 1, v - a[at].second) + a[at].first);
    
    //cout << a[at].first << ' ' << a[at].second << ' ' << mx << endl;
    return memo[at][v] = mn;
}

int main(){
    cin >> N >> W;
    a = vii(N);
    memset(memo, -1, sizeof(memo));
    for (ll i = 0; i < N; i++) {
        cin >> a[i].first >> a[i].second;
    }
    ll best = 0;
    rep(i, 0, 100001){
        ll w = dp(0, i);
        if (w <= W) best = i;
    }
    cout << best;
    return 0;
}


Measured memory_bytes: 82304
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        int[] a = new int[N - 1];
        int[] b = new int[N - 1];
        int[] c = new int[N - 1];
        for (int i = 0; i < N - 1; ++i) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
            c[i] = sc.nextInt();
        }
        int Q = sc.nextInt();
        int K = sc.nextInt() - 1;
        int[] x = new int[Q];
        int[] y = new int[Q];
        for (int i = 0; i < Q; ++i) {
            x[i] = sc.nextInt() - 1;
            y[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a, b, c, x, y, K));

        sc.close();
    }

    static String solve(int[] a, int[] b, int[] c, int[] x, int[] y, int K) {
        int N = a.length + 1;

        @SuppressWarnings("unchecked")
        List<Integer>[] edgeLists = new List[N];
        for (int i = 0; i < edgeLists.length; ++i) {
            edgeLists[i] = new ArrayList<>();
        }

        for (int i = 0; i < a.length; ++i) {
            edgeLists[a[i]].add(i);
            edgeLists[b[i]].add(i);
        }

        long[] distances = new long[N];
        Arrays.fill(distances, -1);
        search(distances, edgeLists, a, b, c, K, 0);

        return IntStream.range(0, x.length).mapToObj(i -> String.valueOf(distances[x[i]] + distances[y[i]]))
                .collect(Collectors.joining("\n"));
    }

    static void search(long[] distances, List<Integer>[] edgeLists, int[] a, int[] b, int[] c, int v, long distance) {
        distances[v] = distance;

        for (int edge : edgeLists[v]) {
            int adj = (a[edge] == v) ? b[edge] : a[edge];
            if (distances[adj] == -1) {
                search(distances, edgeLists, a, b, c, adj, distance + c[edge]);
            }
        }
    }
}

Measured memory_bytes: 187244
s = input()
dp = [[0]*4 for i in range(len(s)+1)]

dp[0][3] = 1
mod = 1000000007

for i in range(1,len(s)+1):
  if s[i-1] == "A":
    dp[i][0] += dp[i-1][0] + dp[i-1][3]
    dp[i][1] += dp[i-1][1]
    dp[i][2] += dp[i-1][2]
    dp[i][3] += dp[i-1][3]
    
  elif s[i-1] == "B":
    dp[i][0] += dp[i-1][0]
    dp[i][1] += dp[i-1][1] + dp[i-1][0]
    dp[i][2] += dp[i-1][2]
    dp[i][3] += dp[i-1][3]
    
  elif s[i-1] == "C":
    dp[i][0] += dp[i-1][0]
    dp[i][1] += dp[i-1][1]
    dp[i][2] += dp[i-1][2] + dp[i-1][1]
    dp[i][3] += dp[i-1][3]
    
  else:
    dp[i][0] += dp[i-1][0]*3 + dp[i-1][3]
    dp[i][1] += dp[i-1][1]*3 + dp[i-1][0]
    dp[i][2] += dp[i-1][2]*3 + dp[i-1][1]
    dp[i][3] += dp[i-1][3]*3
    
  dp[i][0] %= mod
  dp[i][1] %= mod
  dp[i][2] %= mod
  dp[i][3] %= mod

print(dp[len(s)][2])
#print(dp)

Measured memory_bytes: 27644
bingo = []
3.times do
  bingo << gets.split.map(&:to_i)
end
n = gets.to_i
lists = []
n.times do
  lists << gets.to_i

end
3.times do |i|
  3.times do |j|
    if lists.include?(bingo[i][j])
      bingo[i][j] = -1
    end
  end
end
# bingo.each do |bi|
#   p bi
# end

# 3.times do |i|
#   if bingo[i].all?{|x| x == -1}
#     puts "Yes"
#     exit
#   end
# end
# 3.times do |j|
#   3.times do |i|
#     check = true
#     if bingo[i][j] != -1
#       check = false
#     end
#     if check
#       puts "Yes"
#       exit
#     end
#   end
# end
if bingo[0][0] == -1 && bingo[1][1] == -1 && bingo[2][2] == -1
  puts "Yes"
  exit
elsif bingo[0][2] == -1 && bingo[1][1] == -1 && bingo[2][0] == -1
  puts "Yes"
  exit
elsif bingo[0][0] == -1 && bingo[1][0] == -1 && bingo[2][0] == -1
  puts "Yes"
  exit
elsif bingo[0][1] == -1 && bingo[1][1] == -1 && bingo[2][1] == -1
  puts "Yes"
  exit
elsif bingo[0][2] == -1 && bingo[1][2] == -1 && bingo[2][2] == -1
  puts "Yes"
  exit
elsif bingo[0][0] == -1 && bingo[0][1] == -1 && bingo[0][2] == -1
  puts "Yes"
  exit
elsif bingo[1][0] == -1 && bingo[1][1] == -1 && bingo[1][2] == -1
  puts "Yes"
  exit
elsif bingo[2][0] == -1 && bingo[2][1] == -1 && bingo[2][2] == -1
  puts "Yes"
  exit
end
puts "No"

Measured memory_bytes: 1788
from collections import deque


class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = int(time)


def main():
    n, q = map(int, input().split())
    queue = deque()
    for _ in range(n):
        name, time = input().split()
        queue.append(Process(name, time))

    time = 0
    while queue:
        process = queue.popleft()
        if process.time - q > 0:
            process.time -= q
            time += q
            queue.append(process)
        else:
            time += process.time
            print("{} {}".format(process.name, time))


if __name__ == "__main__":
    main()



Measured memory_bytes: 17548