akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
   input! {
       n: usize,
       x: isize,
       pos: [isize; n],
    }

    let first = x - pos[0];
    let ans = pos.iter().map(|c| (c-x).abs()).fold(first, |acc, x| gcd(acc, x));

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

fn gcd(x: isize, y: isize) -> isize {
    //println!("x: {} y: {}", x, y);
    return if x % y != 0 { gcd(y, x%y) } else { y };
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

char S[100011];
int K;
int N;

string T[6];

void MAIN() {
    scanf("%s", S);
    scanf("%d", &K);
    N = strlen(S);

    REP (c, K+1) T[c] = "{";
    REP (i, N) for (int j=i+1; j<=N; j++) {
	T[K] = string(S+i, S+j);

	int pos = lower_bound(T, T+K, T[K]) - T;
	if (pos < K && T[pos] != T[K]) {
	    for (int c=K-1; pos<=c; c--) swap(T[c], T[c+1]);
	}
    }

    puts(T[K-1].c_str());
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
n, m = (int(x) for x in input().split())
sh = input().split(" ")
h = []
for s in sh:
    h.append([int(s), []])
for i in range(m):
    a, b = (int(x) for x in input().split())
    h[a - 1][1].append(b - 1)
    h[b - 1][1].append(a - 1)
cnt = n
for i in h:
    for j in i[1]:
        if i[0] <= h[j][0]:
            cnt -= 1
            break

print(cnt)

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(((a==5)&&(b==5)&&(c==7))||((a==5)&&(b==7)&&(c==5))||((a==7)&&(b==5)&&(c==5))){
    cout <<"YES"<<endl;
    return 0;
  }
  cout<<"NO"<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
ll n,k = 2;
ll memo[100000][3],a[100000][3];
ll dp(ll i,ll prev){
	if(i == n) return 0;
	if(prev!=-1 && memo[i][prev] != -1) return memo[i][prev];
	ll ret = INT_MIN;
	for(int j=0;j<3;j++){
		if(j == prev) continue;
		ret = max(ret,dp(i+1,j)+a[i][j]);
	}
	memo[i][prev] = ret;
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(memo,-1,sizeof(memo));
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	cout<<dp(0,-1)<<"\n";
	return 0;
}

Measured memory_bytes: 11264
//C - Not so Diverse: 
//Assunto: 
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, k, cnt = 0, ans;
    cin >> n >> k;
    vector<int> show(n+1, 0);
    vector<int> balls(n);   
    loop(i, 0, n) {
        cin >> balls[i];
        if(!show[balls[i]]) cnt++;
        show[balls[i]]++;
    }
    if(cnt <= k) ans = 0;
    else {
        sort(all(show));
        ans = 0;
        for(auto x : show) {
            if(x == 0) continue;
            else if(cnt > k) {
                ans += x;
                cnt--;
            } 
            else break;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
int x = 0, y = 0;
int c[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
int main(void){
    std::cin >> x >> y;
    std::cout << ((c[x] == c[y]) ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 764
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,k;
    cin>>a>>b>>k;
    rep(i,k){
        if(i%2==0){
            if(a%2==1) a--;
            a/=2;
            b+=a;
        }
        else{
            if(b%2==1) b--;
            b/=2;
            a+=b;
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            for (var i = 1; i < 10; i++)
            {
                for (var j = 1; j < 10; j++)
                {
                    if (i * j == N)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
            }

            Console.WriteLine("No");
        }
    }
}


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

signed main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  int k = 4000;

  static int a[510][510];
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      a[i][j] = k;
    }
  }
  for (int i = h; i <= H; i += h) {
    for (int j = w; j <= W; j += w) {
      a[i][j] = -(h * w - 1) * k - 1;
    }
  }

  int sum = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      sum += a[i][j];
    }
  }

  if (sum <= 0) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (j != 1) cout << " ";
      cout << a[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define m 1000000007
#define MAXN 1000001
#define satya ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cil(a,b) (((a-1)/b)+1)
//#define init int t;cin>>t;while(t--)
#define in(a) ll a;scanf("%lld",&a)
#define ine(a,b) ll a,b;scanf("%lld lld",&a,&b)



ll spf[MAXN]; 

void sieve1() 
{ 
	spf[1] = 1; 
	for (int i=2; i<MAXN; i++) 

		spf[i] = i; 

	for (int i=4; i<MAXN; i+=2) 
		spf[i] = 2; 

	for (int i=3; i*i<MAXN; i++) 
	{ 
		if (spf[i] == i) 
		{ 
			for (int j=i*i; j<MAXN; j+=i) 

				if (spf[j]==j) 
					spf[j] = i; 
		} 
	} 
} 

ll  getFactorization(int x) 
{ 
	vector<int> ret; 
	long long int p=0;
	while (x != 1) 
	{ 
		ret.push_back(spf[x]); 
		x = x / spf[x]; 
	} 
	sort(ret.begin(),ret.end());
	for(int i=0;i<ret.size()-1;i++) 
	{
	    if(ret[i]!=ret[i+1])
	    p=p+ret[i];
	}
	p=p+ret[ret.size()-1];
	return p;
} 

ll d[1000055],u=0;
void Sieve(int n) 
{ 
	bool prime[n+1]; 
//	ll u=0;
	memset(prime, true, sizeof(prime)); 

	for (int p=2; p*p<=n; p++) 
	{ 
		if (prime[p] == true) 
		{ 
			for (int i=p*2; i<=n; i += p) 
				prime[i] = false; 
		} 
	} 

	for (int p=2; p<=n; p++) 
	if (prime[p]) 
	{
	    d[u]=p;
	    u++;
	}
} 

ll minverse(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return minverse((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*minverse((x*x)%M,(n-1)/2,M))%M;

}
ll prime(ll n){
    ll i;
    if(n==1||n==0)
    return 0;
    for(i=2;i<sqrt(n);i++)
    {
        if(n%i==0)
        return 0;
    }
    return 1;
}
int main() {
       satya;
     //sieve1(); 
     //Sieve(100);
     ll n;
     cin>>n;
     long double a[n],sum=0;
     for(int i=0;i<n;i++){
     cin>>a[i];
     sum+=(1/a[i]);
            //   cout<<sum<<endl;

     }
    //  cout<<sum<<endl;
     sum=(1/sum);
     cout<<fixed<<setprecision(8)<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int d[30][30],n;
int f(int mi,int t){//printf("%d %d",
  int i,j,c[30],u[30]={0};
  for(i=0;i<30;i++)c[i]=1e8;
  c[mi]=0;
  for(i=0;i<n;i++){
    for(j=u[mi]=1;j<=n;j++){
      if(c[j]>c[mi]+d[mi][j])c[j]=c[mi]+d[mi][j];
    }
    for(mi=1;u[mi];mi++);
    for(j=mi;j<=n;j++){
      if(u[j]==0&&c[mi]>c[j])mi=j;
    }
  }
  return c[t];
}
int main(){
  int m,i,j,a,b;
  scanf("%d %d",&n,&m);
  for(i=0;i<900;i++)d[i/30][i%30]=1e8;
  while(m--){
    scanf("%d,%d,",&i,&j);
    scanf("%d,%d",&d[i][j],&d[j][i]);
  }
  scanf("%d,%d,%d,%d",&a,&b,&i,&j);
  printf("%d\n",i-f(b,a)-f(a,b)-j);
  return 0;
}

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

int main() {
  int64_t N;
  string S;
  cin>>N>>S;
  int64_t r=0;
  int64_t g=0;
  int64_t b=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='R') r++;
    else if(S.at(i)=='G') g++;
    else b++;
  }
  int64_t moto=r*g*b;
  int64_t gen=0;
  for(int i=0;i<N;i++){
    int j=1;
    while(i+2*j<N){
      if(S.at(i)!=S.at(i+j)&&S.at(i)!=S.at(i+2*j)&&S.at(i+j)!=S.at(i+2*j)) gen++;
      j++;
    }
  }
  cout<<moto-gen<<endl;
      
      
  
  
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
long long dp[110][4][4][4];

int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<4;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++){
		if(i==0&&j==1&&k==2)continue;
		if(i==0&&j==2&&k==1)continue;
		if(i==1&&j==0&&k==2)continue;
		
		dp[3][i][j][k]=1;
	}
	for(int i=3;i<a;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++)for(int l=0;l<4;l++){
		for(int m=0;m<4;m++){
			if(k==0&&l==1&&m==2)continue;
			if(k==0&&l==2&&m==1)continue;
			if(k==1&&l==0&&m==2)continue;
			if(j==0&&l==1&&m==2)continue;
			if(j==0&&k==1&&m==2)continue;

			dp[i+1][k][l][m]=(dp[i+1][k][l][m]+dp[i][j][k][l])%mod;
		}
	}
	long long ret=0;
	for(int i=0;i<4;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++)ret+=dp[a][i][j][k];
	printf("%lld\n",ret%mod);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

struct UF {
	vector<int>par;//親
	vector<int>Rank;//木の深さ

            UF(int n){init(n);}

	//初期化
	void init(int n) {
		par.resize(n); Rank.resize(n);
		for (int i = 0; i < n; i++) {
			par[i]= i;
			Rank[i] = 0;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;//すでに同じ集合に属している

		if (Rank[x] < Rank[y]) {//高さが小さい方を下に
			par[x] = y;
		}
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
		}
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	int r,d;
    cin>>r>>d;
    vector<int>x(14);
    cin>>x[0];
    rep(i,10){
        x[i+1]=x[i]*r-d;
        cout<<x[i+1]<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
using namespace std;

struct Node {
    int parent;
    int number;
    struct Node *left;
    struct Node *right;
};

struct Node * N[100000];
//void show()
//
int getDepth(struct Node *node){

    int count = 0;

    while (node->parent != -1) {
        count++;
        node = N[node->parent];
    }

    return count;
}

int main() {

    struct Node *node1, *node2, *node3, *prev_node, *parent;
    int n, m, node, parent_number, node_count, child_node;

    cin >> n;

    for (int i = 0; i < n; i++) {
        N[i] = NULL;
    }
    for (int i = 0; i < n; i++) {
        cin >> parent_number;
        cin >> node_count;

        if (N[parent_number] == NULL) {
            node2 = (struct Node*)malloc(sizeof(struct Node));
            node2->number = parent_number;
            node2->right = NULL;
            node2->left = NULL;
            node2->parent = -1;
            N[parent_number] = node2;
        }

        for (int j = 0; j < node_count; j++) {
            cin >> child_node;
            node1 = (struct Node*)malloc(sizeof(struct Node));
            node1->number = child_node;

            // slibing
            if (j == 0) {
                N[parent_number]->left = node1;
            }
            else {
                prev_node->right = node1;
            }


            // parent
            node1->parent = parent_number;

            prev_node = node1;
            //cout << prev_node->number << endl;

            if (N[child_node] == NULL){

                node1->right = NULL;
                node1->left = NULL;
                N[child_node] = node1;

            }
            //else {

            //}
            //cout << "child node " << parent_number;
            N[child_node]->parent = parent_number;

        }
    }
    for (int i = 0; i < n; i++) {
        struct Node *a = N[i];
        struct Node *b;
        cout << "node " << i << ":";
        cout << " parent = " << a->parent;

        // depth
        //
        cout << ", depth = ";
        cout << getDepth(a);

        // type
        if (a->parent == -1) {
            cout << ", root";
        }
        else if (a->left) {
            cout << ", internal node";
        }
        else if (a->left == NULL) {
            cout << ", leaf";
        }



        cout << ", [";
        b = a->left;
        while (b != NULL){
            cout << b->number;
            b = b->right;
            if (b) {
                cout << ", ";
            }
        }
        cout << "]" ;





        cout << endl;
    }


    return 0;

}
 

Measured memory_bytes: 6976
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>

using namespace std;

#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   rush()        int T;scanf("%d",&T);while(T--)
#define   debug         puts("debug")

typedef   pair<int,int> P;

const int   M = 2e5+50;
const int mod = 1e9+7;
const int inf = 1e9;

map<ll,ll> vis;

int main() {

	int n;
	scanf("%d",&n);
	
	ll ans = 0,sum = 0,ch;
	vis[0] = 1;
	
	for(int i=0;i<n;i++) {
		scanf("%lld",&ch);
		sum += ch;
		ans += vis[sum];
		vis[sum]++;
	}
	
	printf("%lld\n",ans);
	
	
	return 0;
}

/*
	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
*/





Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec res(n+1);

    for (int x = 1; x * x <= n; x++) {
        for (int y = 1; y * y + x * x <= n; y++) {
            for (int z = 1; x * x + y * y + z * z <= n; z++) {
                int calc = x * x + y * y + z * z;
                calc += x * y + y * z + z * x;
                if (calc >= 1 && calc <= n) res[calc]++;
            }
        }
    }

    for (int i = 1; i <= n; i++) cout << res[i] << endl;
    return 0;
}

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

int main() {

	int n; cin >> n;
	double ans = 0;
	for (int i = 0; i < n; i++) {
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY") {
			ans += x;
		}
		else {
			ans += x * 380000;
		}
	}


	cout << fixed << setprecision(11) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int a = Integer.parseInt(st[0]);
        int b = Integer.parseInt(st[1]);
        bw.append(a == b ? "a == b\n" : (a < b ? "a < b\n" : "a > b\n"));
        bw.flush();
    }

}


Measured memory_bytes: 24372
n, m = map(int,input().split())
b_list = []

for i in range(m):
    x = []
    x = list(map(int,input().split()))
    b_list.append(x)

ans_list = [0 for i in range(10**5)]
ans_list[0] = 1
ball_list = [1 for i in range(10**5)]

for tmp in b_list:
    x, y = tmp[0], tmp[1]
    if ans_list[x-1] == 1 and ans_list[y-1] == 0:
        ans_list[y-1] += 1
    ball_list[y-1] += 1
    ball_list[x-1] -= 1
    if ball_list[x-1] == 0:
        ans_list[x-1] = 0

ans = 0

for i in ans_list:
    if i == 1:
        ans += 1

print(ans)


Measured memory_bytes: 28832
#include<bits/stdc++.h>
using namespace std;
int trinum[11]={0,1,3,6,10,15,21,28,36,45,55};
int a[10000005]={0};
int main() {
	long long n,sum=0;
	cin>>n;
	if(n==1){
		cout<<0;
		return 0;
	}
	long long j=2;
	int m=int(sqrt(n));
	while(n%2==0){
		n/=2;
		a[2]++;
	}
	int t=3,ans=0;
	while(n!=1&&t<=m){
		while(n%t==0){
			n/=t;
			a[t]++;
		}
		t+=2;
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=10;j++){
			if(trinum[j]>a[i]){
				sum+=(j-1);
				break;
			}
		}
	}
	if(n>1){
		sum++;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3684
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split())) + [0]
c = [0] * (n + 1)

cnt = 0
for i in range(n + 1):
    if a[i] <= b[i] + c[i]:
        cnt += a[i]
        b[i] -= max(0, a[i] - c[i])
        if i < n:
            c[i + 1] = b[i]
    else:
        cnt += b[i] + c[i]

print(cnt)


Measured memory_bytes: 18624
#pragma GCC optimize("Ofast")  
#include<bits/stdc++.h>
using namespace std;

#define ll 				long long
#define eb 				emplace_back
const long long 		MOD = 1e9 + 7;
#define rep(i,n) 		for (int (i) = 0; (i) < (n); (i)++) 
#define REP(i,k,n)  	for (int (i) = (k); (i) <= (n); (i)++) 
#define REPR(i,k,n) 	for (int (i) = (k); (i) >= (n); (i)--)
#define watch(x) 		cout << (#x) << " = " << (x) << endl
#define t(x)			int x; cin >> x; while(x--)

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	
	/*---- continue Coding ;----*/

	string s = "";
	int n;
	cin >> n;
	rep(i, n)
		s += "ACL";
	cout << s << "\n";
	
	/*---- break ;----*/

	cerr<<"Execution time: "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
	return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// }}} End

i64 sigma(i64 n) { return n * (1 + n) / 2; }

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  VAR(i64, n, k);

  vector<i64> a(n);
  rep(i, n) {
    IN(a[i]);
  }

  i64 c1 = 0, c2 = 0;
  rep(i, n) {
    rep(j, i) {
      if (a[j] > a[i]) (c1 += 1) %= MOD;
    }
  }

  rep(i, n) {
    rep(j, n) {
      if (a[j] > a[i]) (c2 += 1) %= MOD;
    }
  }

  c1 *= k;
  c1 %= MOD;
  c2 *= sigma(k - 1) % MOD;
  c2 %= MOD;

  OUTL((c1 + c2) % MOD % MOD);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,K;
    cin>>N>>K;
    cout<<N*K/2<<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int k,n,i,j,x;
	x=0;
	cin>>k>>n;
	long long int ar[n+4];
	for(i=0;i<n;i++){
		cin>>ar[i];
		if(i==0){
			if(ar[i]>x){
				x=ar[i];
			}
		}
		else{
			if(ar[i]-ar[i-1]>x){
				x=ar[i]-ar[i-1];
			}
		}
	}
	if((k-ar[n-1]+ar[0])>x){
		x=k-ar[n-1]+ar[0];
	}
	cout<<k-x<<endl;
	return 0;

}

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

int main()
{
  string s;
  cin >> s;
  char z=0x00;
  bool flag=true;
  for(int i=0;i<4;i++){
    if(z==s[i])
      flag=false;
    z=s[i];
  }
  if(!flag)
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
N,A,B = map(int,input().split())
S = input()

d = 0
o = 0
p = 0

for i in range(N):
  if S[i]=="a":
    d+=1
    if p<A+B:
      p+=1
      print("Yes")
    else:
      print("No")
  elif S[i]=="b":
    o+=1
    if p<A+B and o <= B:
      p+=1
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Measured memory_bytes: 53208
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    aa=LI()
    print(aa.index(0)+1)

main()

Measured memory_bytes: 9132
import math
from functools import reduce


def lcm(x, y):
  return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm, numbers, 1)


N = int(input())
A = list(map(int,input().split()))

MOD = lcm_list(A)-1

ans = 0
for a in A:
  ans += MOD%a
print(ans)

Measured memory_bytes: 9692
#include <stdio.h>
#include <vector>
int n,m;
std::vector<int> V[100010];
int visit[100010];
int cnt;
void dfs(int x){
	visit[x] = 1;
	for(int i=0;i<V[x].size();i++){
		if(visit[V[x][i]]==0){
			dfs(V[x][i]);
		}
	}
}
int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		V[a].push_back(b);
		V[b].push_back(a);
	}
	for(int i=1;i<=n;i++){
		if(visit[i]==0){
			dfs(i);
			cnt++;
		}
	}
	printf("%d\n",cnt-1);
}

Measured memory_bytes: 9532
package main

import (
	"fmt"
	"math"
)

func main(){
	var x int
	fmt.Scan(&x)
	for x <= 100003{
		if is_prime(x) {
			fmt.Printf("%d", x)
			return
		}
		x++
	}
}

func is_prime(n int) bool {
	switch {
	case n < 2:
		return false
	case n == 2 || n == 3 || n == 5:
		return true
	case n & 1 == 0:
		return false
	case n % 2 == 0 || n % 3 == 0 || n % 5 == 0:
		return false
	}

	f := true
	v := 7
	m := int(math.Pow(float64(n), 0.5)) + 1
	for v < m {
			if n % v == 0 {
					return false
			}
			if f {
					v += 4
			} else {
					v += 2
			}
			f = !f
	}
	return true
}

Measured memory_bytes: 512
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int x = sc.nextInt();
      if(a+b < x || a > x) System.out.println("NO");
      else System.out.println("YES");
      sc.close();
    }
}


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

#define fi first
#define se second
#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a (n);
  FOR (i, 0, n) {
    cin >> a[i];
  }
  i64 tot = 0;
  sort (a.begin(), a.end());
  FOR (i, 0, n) {
    FOR (j, i + 1, n) {
      int should = a[i] + a[j];
      auto p = lower_bound (a.begin(), a.end(), should) - a.begin();
      p--;
      tot += p - j;
    }
  }
  cout << tot << '\n';
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> card(110);
  for(int i=0;i<N;i++) cin >> card.at(i);
  sort(card.begin(),card.end(),greater<int>());
  int Alice=0;
  int Bob=0;
  for(int i=0;i<N;i++){
    if(i%2==0){
      Alice+=card.at(i);
    }
    else{
      Bob+=card.at(i);
    }
  }
  cout << Alice-Bob << endl;
}


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

using namespace std;
typedef long long ll;

int main(){
    ll a;
    string s;
    cin >> a;
    cin >> s;
    if(a >= 3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 888
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;
typedef pair<Point, double> Circle;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

double dot(Vector a, Vector b){
    return a.X * b.X + a.Y * b.Y;
}

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

// 円と円の関係（共通接線数）
int intersection(Circle c1, Circle c2){
    double dist = abs(c1.first - c2.first);
    if(c1.second + c2.second < dist) return 4;
    if(equals(c1.second + c2.second, dist)) return 3;
    if(abs(c1.second - c2.second) < dist && dist < c1.second + c2.second) return 2;
    if(equals(abs(c1.second - c2.second), dist)) return 1;
    else return 0;
}

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

    int n; cin>>n;
    while(n--){
        double x1, y1, r1, x2, y2, r2; cin>>x1>>y1>>r1>>x2>>y2>>r2;
        Circle c1 = {Point(x1, y1), r1}, c2 = {Point(x2, y2), r2};
        int num = intersection(c1, c2);

        int ans = -1;
        if(num == 4) ans = 0;
        else if(1 <= num) ans = 1;
        else{
            if(r1 < r2) ans = -2;
            else ans = 2;
        }

        cout << ans << endl;
    }

    return 0;
}


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

int main() {
    int n, m, ans;
    cin >> n >> m;
    ans = (n + m) * (n + m - 1) / 2 - n * m;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String msg = "AC";
		int count = 0;
		int num = 0;

		if (!(s.substring(0, 1).equals("A"))) {
			msg = "WA";
		}

		for (int i = 2; i < s.length() - 1; i++) {
			if (s.substring(i, i + 1).equals("C")) {
				count++;
				if (count > 1) {
					msg = "WA";
					break;
				}
				num = i;
			}
		}
		if (count != 1) {
			msg = "WA";
		}

		for (int i = 1; i < s.length(); i++) {
			if (i == num) {
				continue;
			}
			if (Character.isUpperCase(s.charAt(i))) {
				msg = "WA";
				break;
			}
		}

		System.out.println(msg);

	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<vector<vector<ll> > > dp(m+1, vector<vector<ll> > (n+1, vector<ll> (n+1, 0)));
    dp[0][1][1] = 1;
    for(ll i=0;i<m;i++){
    	for(ll j=0;j<=n;j++){
    		for(ll k=0;k<=n;k++){
    			ll num = dp[i][j][k];
    			if(j != n) (dp[i+1][j+1][k] += (num * (n - j)) % mod) %= mod;
    			(dp[i+1][j][k] += num * (j - k)) %= mod;
    			(dp[i+1][j][j] += num * k) %= mod;
    		}
    	}
    }
    cout << dp[m][n][n] << endl;
    return 0;
}


Measured memory_bytes: 216832
if __name__ == '__main__':
    s = input().split(' ')
    n = int(s[0])
    k = int(s[1])
    a = 0
    for l in range(1, min(n + 1, k)):
        count = 0
        ll = l
        while True:
            ll = ll * 2
            count = count + 1
            if ll >= k:
                a = a + (1 / (2**count))
                break
    if n < k:
        print(a * (1 / n))
    else:
        print((a * (1 / n)) + ((n - k + 1)/n))


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

int main() {
  double N, D;
  cin >> N >> D;
  double X, Y;
  double a = D*D;
  int answer = 0;
  for(int i=0;i<N;i++) {
    cin >> X >> Y;
    double b=X*X + Y*Y;
    if(b <= a) {
      answer++;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 3784
import itertools
 
n, m, q = map(int, input().split())
abcd = [list(map(int, input(). split())) for _ in range(q)]
 
points = []
for able in itertools.combinations_with_replacement(range(1, m+1), n):
    point = 0
    for a, b, c, d in abcd:
        if able[b-1] - able[a-1] == c:
            point += d
    points.append(point)
 
print(max(points))

Measured memory_bytes: 12496
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

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

using namespace std;
typedef long long int ll;
const int INF = 100000000;

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

    if (a >= 3200) {
        cout << s << endl;
    }
    else {
        cout << "red" << endl;
    }
    return 0;
}

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


vector<int> graph[100010] = {};
bool used[100010] = {};

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

  int a, b;
  for(int i = 0;i < m;i++){
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  stack<int> st;
  st.push(1);

  int num = 1;
  used[1] = true;
  while(1){
    int old = st.size();
    for(int i = 0;i < graph[num].size();i++){
      if(used[graph[num][i]] == false){
        st.push(graph[num][i]);
        num = graph[num][i];
        used[num] = true;
        break;
      }
    }
    if(old == st.size()){
      break;
    }
  }

  queue<int> que;

  while(!st.empty()){
    que.push(st.top());
    st.pop();
  }

  num = 1;
  while(1){
    int old = que.size();
    for(int i = 0;i < graph[num].size();i++){
      if(used[graph[num][i]] == false){
        que.push(graph[num][i]);
        num = graph[num][i];
        used[num] = true;
        break;
      }
    }
    if(old == que.size()){
      break;
    }
  }

  cout << que.size() << endl;
  while(!que.empty()){
    cout << que.front();
    que.pop();
    if(!que.empty()){
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    ll diff = B - A;

    bool ok = false;
    for (int k=0; k<=N-1; k++) {
        if (k * C - (N - 1 - k) * D <= diff && diff <= k * D - (N - 1 - k) * C) {
            ok = true;
            break;
        }
    }

    cout << (ok ? "YES" : "NO") << endl;
}

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

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

    std::vector<int> d(n);
    for (int i = 0; i < n; i++) {
        std::cin >> d[i];
    }

    std::sort(d.begin(), d.end());
    d.erase(std::unique(d.begin(), d.end()), d.end());

    std::cout << d.size() << std::endl;
}


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

using namespace std;

const int MAX_N = 5000;

int as[MAX_N+1];

int main ( void )
{
	int n;
	while (cin >> n, n) {
		as[0] = 0;
		for (int i = 0; i < n; ++i) {
			int x;
			cin >> x;
			as[i+1] = as[i] + x;
		}

		int ans = -(1 << 29);
		for (int i = 0; i < n; ++i) {
			for (int j = i+1; j <= n; ++j) {
				ans = max(ans, as[j] - as[i]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
=begin
def dfs(i, p)
  cnt = 
    if p
      V[p][:cnt]
    else
      0
    end

  V[i][:cnt] += cnt

  V[i][:link].each do |l|
    next if l == p
    dfs(l, i)
  end
end
=end

N, Q = gets.strip.split(" ").map(&:to_i)
V = Array.new(N) do |i|
  {cnt: 0, link: []}
end

(N - 1).times do
  a, b = gets.strip.split(" ").map(&:to_i)
  a -= 1
  b -= 1

  V[a][:link] << b
  V[b][:link] << a
end

Q.times do
  p, x = gets.strip.split(" ").map(&:to_i)
  V[p - 1][:cnt] += x
end

# dfs(0, nil)

q = [[0, nil]]
while !q.empty? do
  i, p = q.shift
  cnt =
    if p
      V[p][:cnt]
    else
      0
    end

  V[i][:cnt] += cnt

  V[i][:link].each do |l|
    next if l == p
    q << [l, i]
  end
end

ans = ""
V.each do |v|
  if ans.empty?
    ans << v[:cnt].to_s
  else
    ans << " #{v[:cnt]}"
  end
end

puts ans


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

const int MAX_H = 1e4;
const int MAX_N = 1e3;
const int INF = 1e9;
vector<vector<int> > memo(MAX_N + 1, vector<int>(MAX_H+1, INF));
vector<pair<int, int> > magic(MAX_N + 1);
int dp(int i, int j) {
    if (memo[i][j] == INF) {
        int a = magic[i].first;
        int b = magic[i].second;
        if (i == 0) {
            memo[i][j] = dp(i, max(j-a, 0)) + b;
        } else {
            memo[i][j] = min(dp(i-1, j), dp(i, max(j-a, 0)) + b);
        }
    }
    return memo[i][j];
}

int main() {
    int H, N; cin >> H >> N;
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        magic[i] = {a, b};
    }
    for (int i = 0; i < N; i++) memo[i][0] = 0;
    cout << dp(N-1, H) << endl;
}

Measured memory_bytes: 40064
#include<stdio.h>

int main(){
	char masu[15][15];
	int i,j;
	
	while(scanf("%c", &masu[0][0]) != EOF){
		for(i=1;i<9;i++)scanf("%c", &masu[0][i]);
		
		for(i=1;i<8;i++){
			for(j=0;j<9;j++){
				scanf("%c", &masu[i][j]);
			}
		}
		scanf("%c", &masu[15][15]);
		for(i=0;i<8;i++){
			for(j=0;j<8;j++){
				if(masu[i][j]=='1'   && masu[i+1][j]=='1' && masu[i][j+1]=='1'   && masu[i+1][j+1]=='1')puts("A");
				if(masu[i][j]=='1'   && masu[i+1][j]=='1' && masu[i+2][j]=='1'   && masu[i+3][j]=='1')  puts("B");
				if(masu[i][j]=='1'   && masu[i][j+1]=='1' && masu[i][j+2]=='1'   && masu[i][j+3]=='1')  puts("C");
				if(masu[i][j+1]=='1' && masu[i+1][j]=='1' && masu[i+2][j]=='1'   && masu[i+1][j+1]=='1')puts("D");
				if(masu[i][j]=='1'   && masu[i][j+1]=='1' && masu[i+1][j+1]=='1' && masu[i+1][j+2]=='1')puts("E");
				if(masu[i][j]=='1'   && masu[i+1][j]=='1' && masu[i+1][j+1]=='1' && masu[i+2][j+1]=='1')puts("F");
				if(masu[i][j+1]=='1' && masu[i+1][j]=='1' && masu[i][j+2]=='1'   && masu[i+1][j+1]=='1')puts("G");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))


using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

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

  ll a, b, k;
  cin >> a >> b >> k;
  ll new_a = max((ll)0, a-k);
  b = max((ll)0, (b-max((ll)0, k-a)));
  cout << new_a << ' ' << b << ende;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

struct mi {
  int val; static const int MOD = 1e9+7; static_assert(MOD > 0, "Modulus not set!");
  mi(int v=0) : val(v) { if ((val %= MOD) < 0) val += MOD; }
  mi& operator += (const mi& b) { (val += b.val) %= MOD; return *this; }
  mi& operator -= (const mi& b) { return (*this) += MOD-b.val; }
  mi& operator *= (const mi& b) { val = ((ll)val*(ll)b.val) % MOD; return *this; }
  mi& operator /= (const mi& b) { return (*this) *= b.pow(MOD-2); }
#define _op(op, op2) mi operator op (const mi& b) const { mi ans = *this; return ans op2 b; }
  _op(+, +=); _op(-, -=); _op(*, *=); _op(/, /=);
#undef _op
  mi pow(ll e) const { mi res(1), b(*this); for (; e>0; e/=2, b*=b) { if (e&1) res*=b; } return res; }
  int toInt() const { return val; }
};

const int N = 1e5+5;
vector<int> adj[N];
vector<int> child[N];
int n;

void dfs(int u, int p) {
  for (int v : adj[u]) {
    if (v == p) continue;
    child[u].push_back(v);
    dfs(v, u);
  }
}

mi dp[N][2];
bool vis[N][2];

mi solve(int u, int c) {
  if (!vis[u][c]) {
    dp[u][c] = 1;
    for (int v : child[u]) {
      mi ways = solve(v, 0);
      if (c == 0) {
        ways += solve(v, 1);
      }
      dp[u][c] *= ways;
    }
    vis[u][c] = 1;
  }
  return dp[u][c];
}

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n-1; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  cout << (solve(1, 0) + solve(1, 1)).toInt() << nl;

  return 0;
}



Measured memory_bytes: 20480
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll h, w, k; cin >> h >> w >> k;
  ll state = 1LL<<(w-1);
  vvll dp(h+1, vll(w, 0)); dp[0][0] = 1;
  rep(i, 1, h+1) {
    REP(s, state) {
      bool is_valid = true;
      rep(wi, 0, w-2) if (((s>>wi)&1) && ((s>>(wi+1))&1)) {is_valid=false;break;}
      if (!is_valid) continue;
      if (!(s&1)) {dp[i][0] += dp[i-1][0]; if(dp[i][0]>=MOD) dp[i][0]-=MOD;}
      else {dp[i][0] += dp[i-1][1]; if(dp[i][0]>=MOD) dp[i][0]-=MOD;}
      rep(wi, 0, w-2) {
        if ((s>>wi)&1) {dp[i][wi+1] += dp[i-1][wi]; if(dp[i][wi+1]>=MOD) dp[i][wi+1]-=MOD;}
        else if ((s>>(wi+1))&1) {dp[i][wi+1] += dp[i-1][wi+2]; if(dp[i][wi+1]>=MOD) dp[i][wi+1]-=MOD;}
        else {dp[i][wi+1] += dp[i-1][wi+1]; if(dp[i][wi+1]>=MOD) dp[i][wi+1]-=MOD;}
      }
      if ((s>>(w-2))&1) {dp[i][w-1] += dp[i-1][w-2]; if(dp[i][w-1]>=MOD) dp[i][w-1]-=MOD;}
      else {dp[i][w-1] += dp[i-1][w-1]; if(dp[i][w-1]>=MOD) dp[i][w-1]-=MOD;}
    }
  }
  if (w==1) cout << 1 << endl;
  else cout << dp[h][k-1] << endl;
  return 0;
}

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

int main ()
{
    int n, k, i, c = 0;
    cin >> n >> k;
    int a[n];

    for(i=0; i<n; i++)
        cin >> a[i];
    
    sort(a, a+n);
    for(i=0; i<k; i++)
        c += a[i];
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        HashSet<string> W = new HashSet<string>();
        var w = Console.ReadLine();
        W.Add(w);
        char last = w.Last();
        bool frag = true;
        for (int i = 1; i < N; i++)
        {
            var r = Console.ReadLine();
            if (r[0] != last) frag = false;
            if (W.Contains(r)) frag = false;
            else W.Add(r);
            last = r.Last();
        }
        Console.WriteLine(frag?"Yes":"No");
    }
}

Measured memory_bytes: 28304
#include <iostream>
using namespace std;
 
int main()
{
  int n, k;
  cin >> n >> k;
  int num = 1;
  for(int i = 0; i < n; i++){
    if(num < k){
      num *= 2;
    }
    else{
      num += k;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
n = int(input())
lst = list(map(int,input().split()))


tmp = 0
ans = 0

for i in range(n):
    if i==0:
        tmp = lst[i]
        ans += 1
    else:
        if lst[i] <= tmp:
            ans += 1
        if lst[i] <= tmp:
            tmp = lst[i]
print(ans)

Measured memory_bytes: 24744
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template <typename H> void print(H head) { std::cout << head << std::endl; }
template <typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  std::string ss, t;
  std::cin >> ss >> t;

  std::string s;
  bool is_matched = false;
  for (ll i = (ll)ss.size() - (ll)t.size(); i >= 0; i--) {
    is_matched = true;
    s = ss;
    for (ll j = 0; j < (ll)t.size(); j++) {
      if (ss[i+j] != t[j] && ss[i+j] != '?') {
	is_matched = false;
      }
      s[i+j] = t[j];
    }
    if (is_matched) {
      break;
    }
  }

  if (is_matched) {
    for (ll i = 0; i < (ll)s.size(); i++) {
      if (s[i] == '?') s[i] = 'a';
    }
    print(s);
  } else {
    print("UNRESTORABLE");
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,zh,ans;
int main()
{
	cin>>a>>b;
	zh=a;
	ans=0;
	while(zh<=b)
	{
		ans++;
		zh*=2;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256