akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
#define MOD 1000000007
#define SIZE 100005

using namespace std;

ll inv[SIZE],fac[SIZE],finv[SIZE];
void make(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<SIZE;i++){
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C (int a,int b) {
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
int main(){
  int n;
  cin >> n;
  if(n==1){
    cout << 1 << endl;
    cout << 1 << endl;
    return 0;
  }
  int a[n+1], b[n+1];
  int r = 0, l = n;
  int two;
  FOR(i,0,n+1) a[i] = 0;
  FOR(i,0,n+1) {
    cin >> b[i];
    a[b[i]]++;
    if(a[b[i]] == 2) two = b[i];
  }
  FOR(i,0,n+1){
    if(b[i] == two){
      r = max(r,i);
      l = min(l,i);
    }
  }
  int rl = l + n - r;
  make();
  FOR(k,1,n+2){
    ll ret = C(n + 1, k);
    if(k - 1 <= rl) ret -= C(rl, k - 1);
    if(ret < 0) ret += MOD;
    cout << ret << endl;
  }
  return 0;
}

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

using namespace std;


#define INF (1000000000 + 1)




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

	vector <vector<int>> d(N, vector<int>(N, INF));

	for (int i = 0; i < M; i++) {
		int A, B, C;
		cin >> A >> B >> C;
		d[A - 1][B - 1] = C;
		d[B - 1][A - 1] = C;
	}

	for (int i = 0; i < N; i++) {
		d[i][i] = 0;
	}

	/* Warshall-floyd 最短距離 */
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	/* 給油コストに変換 */
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j)				d[i][j] = 0;
			else if (d[i][j] <= L)	d[i][j] = 1;
			else					d[i][j] = INF;
		}
	}
	/* Warshall-floyd 最小給油コスト */
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int s, t;
		cin >> s >> t;
		if (INF == d[s - 1][t - 1]) cout << -1 << endl;
		else						cout << d[s - 1][t - 1] - 1 << endl;
	}
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
const double PI=acos(-1);

using namespace std;
int main() {
    ll N,K;
    cin>>K>>N;
    vec A(N),B(N);
    rep(i,0,N) {
        cin>>A[i];
    }
    sort(A);
    rep(i,0,N-1) {
        B[i]=A[i+1]-A[i];
    }
    sort(B);
    reverse(B);
    ll count=0;
  
    rep(i,0,min(K-1,N-1)) {
        count+=B[i];
        //cout<<B[i]<<endl;
    }
    ll a=A[N-1]-A[0];
    
    a-=count;
    cout<<a<<endl;
    }

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

using ll = long long;

constexpr ll INF = 1'010'000'000'000'000'017LL;
constexpr ll MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(ll i = (start); i < end; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }

template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
using pint = pair<int, int>;
using pll = pair<ll, ll>; using vp = V<pll>;

ll mod(ll val, ll m){ ll res = val % m; if(res < 0) res += m; return res;}
ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u;}
ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }


//---------------------------------------------------------------

void Main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B && A == C){
        cout << "No" << endl;
    }else if(A != B && B != C && C != A){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

//---------------------------------------------------------------
int main()
{
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] card = new int[3][3];
		boolean[][] hit = new boolean[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				card[i][j] = sc.nextInt();
				hit[i][j] = false;
			}
		}

		List<Integer> list = new ArrayList<>();
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (list.contains(card[i][j])) {
					hit[i][j] = true;
				}
			}
		}
		boolean bingo = //
				(hit[0][0] && hit[0][1] && hit[0][2]) || //
						(hit[1][0] && hit[1][1] && hit[1][2]) || //
						(hit[2][0] && hit[2][1] && hit[2][2]) || //
						(hit[0][0] && hit[1][0] && hit[2][0]) || //
						(hit[0][1] && hit[1][1] && hit[2][1]) || //
						(hit[0][2] && hit[1][2] && hit[2][2]) || //
						(hit[0][0] && hit[1][1] && hit[2][2]) || //
						(hit[0][2] && hit[1][1] && hit[2][0]);
		if (bingo) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  k = min(k, n-1);
  combination c(n);
  mint ans;
  for (int i = 0; i <= k; i++) {
    ans += c(n,i) * c((n-i-1)+i, i);
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N, M, K;
	cin >> N >> M >> K;
	bool ok{};
	rep(i,N+1){
		rep(j,M+1){
			int x = (M-j) * i + (N-i) * j;
			if(K == x) ok = true;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
}

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

int N, cnt = 0;
string S, tmp;

int main(){

    cin >> N >> S;

    for (int i=0; i<N-2; i++){
        if ((S.at(i)=='A') && (S.at(i+1)=='B') && (S.at(i+2)=='C')){
            cnt++;
        }
    }

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

Measured memory_bytes: 256
package main

import (
  "fmt"
  "strconv"
)

func main() {
    var a, b int
    fmt.Scan(&a, &b)
	c := strconv.Itoa(a)+strconv.Itoa(b)
    //fmt.Print(c)
  
  i, _ := strconv.Atoi(c)
	//fmt.Println(i)
  
 	x := 0
 	answer := 0
	hit := false
 	for (x * x) < i { 
    	x++
      	answer = x * x
      if (answer == i){
        hit = true
      }
	    //fmt.Println("Value of i is now:", answer)
	}
  if hit {
    fmt.Println("Yes")
  }else{
    fmt.Println("No")
  }
}


Measured memory_bytes: 512
use std::io;

fn main() {
    let mut index = 1;
    loop {
        let number = input_number();
        if number == 0 { break }
        println!("Case {}: {}", index, number);
        index += 1;
    }
}

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

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

    let input: i32 = input.trim().parse()
        .expect("Failed to parse");
    
    input
}

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

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

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

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

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



Measured memory_bytes: 5052
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		int Ca=1;
		while(sc.hasNext())
		{
			int W = sc.nextInt();
			if(W==0)
				return;
			int n= sc.nextInt();
			int p[] = new int[n+1];
			int w[] = new int[n+1];
			for(int i=1; i<=n; i++)
			{
				String str[] = sc.next().split(",");
				p[i]= Integer.valueOf(str[0]);
				w[i]= Integer.valueOf(str[1]);
			}
			int opt[][] = new int[n+1][W+1];
			for(int i=0; i<=W; i++)
				opt[0][i]=0;
			int maxp = Integer.MIN_VALUE;
			int minw = Integer.MAX_VALUE;
			for(int i=1; i<=n;i++)
				for(int j=0; j<=W; j++)
				{
					if(j-w[i]>=0)
					{
						opt[i][j]=Math.max(opt[i-1][j], opt[i-1][j-w[i]]+p[i]);
						if(maxp<opt[i][j])
						{
							maxp=opt[i][j];
							minw=j;
						}
						else if(maxp==opt[i][j])
						{
							minw=Math.min(minw, j);
						}
					}
					else
						opt[i][j]=opt[i-1][j];
				}
			System.out.println("Case "+Ca+++":");
			System.out.println(maxp);
			System.out.println(minw);
		}
	}
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
	int n;
	vector<T> d;
	BIT(int n=0):n(n),d(n+1) {}
	void add(int i, T x=1) {
		for (i++; i <= n; i += i&-i) {
			d[i] += x;
		}
	}
	T sum(int i) {
		T x = 0;
		for (i++; i; i -= i&-i) {
			x += d[i];
		}
		return x;
	}
	T sum(int l, int r) {
		return sum(r-1) - sum(l-1);
	}
};
int main()
{
	int n, d, a;
	cin >> n >> d >> a;
	vector<P> p(n);
	rep(i,n) cin >> p[i].first >> p[i].second;
	sort(p.begin(),p.end());

	BIT<ll> bit(n+1);
	ll ans = 0;
	rep(i,n) {
		ll x = p[i].first;
		ll h = p[i].second;
		h -= bit.sum(i);
		if (h <= 0) continue;
		ll num = (h+a-1)/a;
		ans += num;
		ll damage = num*a;
		bit.add(i,damage);
		int rx = min(x+d*2, 1001001001ll);
		int j = upper_bound(p.begin(),p.end(), P(rx+1,-1)) - p.begin();
		bit.add(j, -damage);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int n,k;
  cin >> n >> k;
  int ans = 0;
  while(n>=1){
    n/=k;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
int h1,h2,k1,k2;
int a,b,c,d;
cin>>h1>>h2>>k1>>k2;
cin>>a>>b>>c>>d;
int z1,z2;
z1=a*h1+b*h2+(h1/10)*c+(h2/20)*d;
z2=a*k1+b*k2+(k1/10)*c+(k2/20)*d;
if(z1>z2){
 cout<<"hiroshi"<<endl;
}else if(z1<z2){
 cout<<"kenjiro"<<endl;
}else{
 cout<<"even"<<endl;
}
return 0;
}


Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		for(int i=1; i<=n; i++) {
			if(i%3==0 || i%10==3) {
				System.out.print(" " + i);
				continue;
			}
			int j = i/10;
			while(j!=0) {
				if(j%10==3) {
					System.out.print(" " + i);
					break;
				}
				j/=10;
			}
		}
		System.out.println();
	}
}









Measured memory_bytes: 28548
import java.util.*;

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

        Set<String> kh = new HashSet<String>();
        while(sc.hasNext()){
            kh.add(sc.next());
        }
        System.out.println(kh.size());
    }
}

Measured memory_bytes: 69776
// finish date: 2018/01/27
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define bigmod 1000000007
#define INF 1050000000


int main() {
    int N, A;
    cin >> N >> A;
    vi x(N);
    rep(i, N) cin >> x[i];
    ll dp[N + 1][50 * N + 1][N + 1];
    rep(i, N + 1) rep(j, 50 * N + 1) rep(k, N + 1) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    //sort(x.begin(), x.end());
    rep(i, N) {
        rep(j, 50 * i + 1) {
            rep(k, i + 1) {
                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j + x[i]][k + 1] += dp[i][j][k];
            }
        }
    }

    ll ans=0;
    FOR(i,1,N+1){
        ans += dp[N][A*i][i];
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 51072
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = n * a;
        System.out.println(sum > b ? b : sum);
    }
}

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

const int BITS = 31;

vector<long long int> memo(BITS);
long long int power(int i) {return memo[i] = (i == 0 ? 1 : 2 * power(i - 1));}

int Dijkstra(long long int s, long long int d) {
  typedef tuple<int, long long int> Node;

  bitset<BITS> start(s > 0 ? s : -s);

  unordered_set<long long int> visited;
  priority_queue<Node, vector<Node>, greater<Node>> q;
  q.emplace(0, s);
  while(!q.empty()) {
    int step;
    long long int station;
    tie(step, station) = q.top();
    q.pop();
    if(station == d) return step;
    visited.insert(station);

    for(int i = BITS - 1; 0 <= i; --i) {
      if(station != 0 && (station % power(i)) != 0) continue;
      long long int next = station + power(i);
      if(d < next) continue;
      if(visited.count(next)) continue;
      q.emplace(step + 1, next);
      break;
    }
  }

  return 0;
};

int main() {
  int N;
  cin >> N;
  for(int i = 0; i < N; ++i) {
    long long int s, d;
    cin >> s >> d;

    cout << Dijkstra(s, d) << endl;
  }
}

Measured memory_bytes: 1216
#include<cstdio>
#include<algorithm>
using namespace std;

char s1[200001],s2[200001];
int main(){
	int n,m,k;
	int x,y;
	scanf("%d%d%d",&n,&m,&k);
	scanf("%d%d%s%s",&x,&y,s1+1,s2+1);
	int l1=1,r1=n,l2=1,r2=m;
	for(int i=k;i;i--){
		if(s2[i]=='U')r1=min(n,r1+1);
		if(s2[i]=='D')l1=max(1,l1-1);
		if(s2[i]=='L')r2=min(m,r2+1);
		if(s2[i]=='R')l2=max(1,l2-1);
		if(s1[i]=='U')l1++;
		if(s1[i]=='D')r1--;
		if(s1[i]=='L')l2++;
		if(s1[i]=='R')r2--;
		//printf("%d %d %d %d\n",l1,r1,l2,r2);
		if(l1>r1||l2>r2){
			printf("NO\n");
			return 0;
		}
	}
	if(x>=l1&&x<=r1&&y>=l2&&y<=r2)
		printf("YES\n");
	else printf("NO\n");
}

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


// #define REP(i, x) for (int i = 0; i < (int)(x); i++)
// #define ALL(x) (x).begin(), (x).end()

// typedef long long ll;
// using namespace std;

// int main() {
//   cin.tie(0);
//   ios::sync_with_stdio(false);
  
//   ll A, B;
//   cin >> A >> B;

//   vector<int> candidates;

//   for(int i=1; i < max(sqrt(A), sqrt(B)); ++i){
//     if((A % i == 0) && (B % i == 0)){
//       candidates.push_back(i);
//     }
//   }

//   ll result = 0;
//   for(int i=0; i < candidates.size(); ++i){
//     for(int j = i+1; j<candidates.size(); ++j){
//       cout << candidates[i] << ":" << candidates[j] << ":" << __gcd(candidates[i], candidates[j])  << endl;

//       if(__gcd(candidates[i], candidates[j]) == 1){
//         ++result;
//       }
//     }
//   }

//   cout << result << endl;

//   return 0;
// }


#include<iostream>
#include<cmath>
#include<vector>
long long gcd(long long a,long long b){
    while(a && b){
        if(a > b)a%=b;
        else b%=a;
    }
    return a+b;
}

int main(){
    long long a,b;
    long long ans=0; 
    std::cin>>a>>b;

    const long long C = gcd(a,b);
    long long c = C;

    for(int i=2;i<std::sqrt(C);i++){
        if(c%i==0){
            ans++;
            while(c%i==0)c/=i;
        }
    }
    if(c!=1)ans++;
    std::cout<<ans+1<<std::endl;
}


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

int main(){
    ll n,k;
    cin >> n >> k;
    vector <ll> dp(3*n,0);
    ll wa=0;

    vector <ll> l(k),r(k);
    rep(i,k){
        cin >> l[i] >> r[i];
        ++r[i];
    }

    dp[1]=1;
    dp[2]=-1;
    ll mod=998244353;

    rep(i,n+1){
        wa+=dp[i];
        //cout << wa << endl;
        wa=wa%mod;
        rep(j,k){
            dp[i+l[j]]+=wa;
            dp[i+l[j]]=dp[i+l[j]]%mod;
            
            dp[i+r[j]]-=wa;
            dp[i+r[j]]=dp[i+r[j]]%mod;
            
        }
    }

    if(wa<0){
        wa+=mod;
    }

    cout << wa << endl;

    
    

    return 0;
}

Measured memory_bytes: 7936
# Your code here!
a = input()
b = input()

if a[0] == b[2]:
    if a[1] == b[1]:
        if a[2] == b[0]:
            print("YES")
        else:
            print("NO")
            
    else:
        print("NO")
        
else:
    print("NO")
    

Measured memory_bytes: 2940
# ABC096 D - Five, Five Everywhere
def isPrime(p):
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            return False
    return True
n=int(input())
p=[]
ans=[]
for i in range(2,55556):
    if isPrime(i):
        p.append(i)

for i in range(len(p)):
    if len(ans)<n:
        if p[i]%5==1:
            ans.append(p[i])
    else:
        break

print(*ans)



Measured memory_bytes: 3572
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

s = 0
for i in range(N):
    if Bs[i] > As[i]:
        s += As[i]
        Bs[i] -= As[i]
    else:
        s += Bs[i]
        Bs[i] = 0
    if Bs[i] > As[i + 1]:
        s += As[i + 1]
        As[i + 1] = 0
    else:
        s += Bs[i]
        As[i + 1] -= Bs[i]
print(s)

Measured memory_bytes: 82020
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr, n);
  console.log(arr.reduce((s, e) => s += ` ${e}`, ''));
})();

function buildMaxHeap(arr, n) {
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(n / 2); i > -1; i--) maxHeapify(i);
}



Measured memory_bytes: 140144
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
 
int main() {
	FASTIO

	int n, x, t;
	cin >> n >> x >> t;
	int ans = ((n/x) + (n%x != 0))*t;
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 3652
let rec gcd a b =
    if a == b then a 
    else if a < b then gcd a (b-a)
    else if a > b then gcd (a-b) b
    else 0

let lcm a b =
     (a * b) / (gcd a b)

let () =
    try
        while true do
            let a, b     = Scanf.scanf "%d %d\n" (fun a b -> a, b) in
            let gcd, lcm = (gcd a b), (lcm a b) in
            Printf.printf "%d %d\n" gcd lcm
        done
    with
        End_of_file -> ()

Measured memory_bytes: 2308
import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
Graph = [[] for i in range(n)]
seen = [False]*n
point = [0]*n


def dfs(g, v, p):
    # vを訪問済みにする
    seen[v] = True
    if p != -1: point[v] += point[p]

    # vから行ける各頂点について
    for next_v in g[v]:

        # next_vが訪問済みだったらスルー
        if seen[next_v]: continue

        # 再帰的に探索
        dfs(g, next_v, v)


for i in range(n-1):
    a, b = map(int, input().split())
    a-=1
    b-=1

    # 無向グラフを想定
    Graph[a].append(b)
    Graph[b].append(a)


for i in range(q):
    x, p = map(int, input().split())
    point[x-1] += p


dfs(Graph, 0, -1)


print(*point)


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

int n, a, b, c, d;
string s;

bool exist2blocks(int begin, int end)
{
    for (int i = begin; i < end; i++)
    {
        if (s[i] == '#' && s[i + 1] == '#')
        {
            return true;
        }
    }
    return false;
}

bool exist3frees(int begin, int end)
{
    if (begin != 0) begin--;
    if (end < s.size()) end++;
    for (int i = begin; i < end - 1; i++)
    {
        if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.')
        {
            return true;
        }
    }
    return false;
}

int main()
{
    cin >> n >> a >> b >> c >> d;
    cin >> s;
    a--;
    b--;
    c--;
    d--;
    if (exist2blocks(a, c) || exist2blocks(b, d))
    {
        cout << "No" << endl;
    }
    else
    {
        if (c < d)
        {
            cout << "Yes" << endl;
        }
        else
        {
            if (exist3frees(b, d))
            {
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 640
import std.stdio, std.conv, std.string, std.algorithm, std.range;

void main() {
  auto N = readln.split[0].to!int;
  auto A = new int[N];
  auto B = readln.split.to!(int[]);

  A[0] = B[0];
  A[$-1] = B[$-1];
  for(auto i = 1; i < A.length - 1; i++) {
    A[i] = min(B[i-1], B[i]);
  }

  A.reduce!"a+b"().writeln;
}

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

int main(){
    int N,K;
    scanf("%d%d",&N,&K);
    char S[N];
    scanf("%s",S);

    int ans = 0;
    vector<int> start ={0};
    vector<int> end;
    int low = 0;
    int find_k = 0;

    if(S[0] == '0'){
        for(int i =0;i < N;i++){
            if(S[i] == '1'){
                start.push_back(i);
                find_k++;
                break;
            }
        }
    }

    for(int i =start.back() +1;i <N;i++){
        if(S[i-1] =='0' && S[i] == '1'){
            start.push_back(i);
        }
        if(S[i-1] =='1' && S[i] == '0'){
            find_k++;
            if(find_k > K){
                end.push_back(i);
                find_k = K;
            }
        }
    }
    end.push_back(N);

    for(int i = 0;i < end.size();i++){
        ans = max(ans,end[i]-start[i]);
//      printf("i:start = %d,end = %d\n",start[i],end[i]);
    }
    printf("%d",ans);
    

    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define ii pair<int,int>
#define ll long long

using namespace std;

int main(){
    int n;cin>>n;
    vector<int>a(n),b(n),c(n-1);
    for(int i = 0;i<n;i++){
        cin>>a[i];
        a[i]--;
    }
    for(int i= 0;i<n;i++){
        cin>>b[i];
    }
    for(int i = 0;i<n-1;i++){
        cin>>c[i];
    }
    int ans = b[a[0]];
    for(int i = 1;i<n;i++){
        ans+=b[a[i]];
        if(a[i-1]+1 == a[i])ans+=c[a[i-1]];
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=n-1;i > m;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main() {
  lli A,B,C,D,E,F=1,N,M,K,sum=0,num=0,ans=0;
  cin >> N;
  vector<int>P(N,0);
  rep(i,0,N)cin >>P[i];
  rep(i,1,N)if(P[i-1]>P[i])sum+=P[i-1]-P[i];
  Out(sum+P[N-1]);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
#define LATTE 100000

struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x=_x; y=_y;
    }
};
 
struct Line{
    double x[2],y[2];
    Line(){}
    Line(Point p,Point q){
        x[0]=p.x; x[1]=q.x;
        y[0]=p.y; y[1]=q.y;
    }
};
 
void RevXY(Point &p){
    swap(p.x,p.y);
}
 
void RevXY(Line &l){
    for(int i=0;i<2;i++) swap(l.x[i],l.y[i]);
}
 
bool Is_SameSide(Line l,Point p,Point q){
    if(l.x[1]==l.x[0]){
        RevXY(l); RevXY(p); RevXY(q);
    }
    double a,b;
    a = (l.y[1]-l.y[0])/(l.x[1]-l.x[0]);
    b = l.y[0]-a*l.x[0];
    if((p.y-(a*p.x+b))*(q.y-(a*q.x+b))>0) return true;
    else return false;
}

int main(){
	Point P[100];
	int N,ans;
	while(cin>>N,N){
		bool used[100]={};
		ans = N;
		for(int i=0;i<N;i++){
			scanf("%lf,%lf",&P[i].x,&P[i].y);
		}
		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
				Point p(LATTE,LATTE);
				Line l(P[i],P[j]);
				bool flag=true;
				for(int k=0;k<N;k++){
					if(i==k || j==k) continue;
					if(p.x==LATTE){
						p = P[k];
						continue;
					}
					if(Is_SameSide(l,p,P[k])==false){
						flag = false;
						break;
					}
				}
				if(flag==true){
					if(used[i]==false) ans--;
					used[i] = true;
					if(used[j]==false) ans--;
					used[j] = true;
				}
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1256
num=list(map(int,input().split()))

A=num[0]
B=num[1]
C=num[2]

if A==7:
    if (B==5)and(C==5):
        print("YES")
    else:
        print("NO")
elif B==7:
    if (A==5)and(C==5):
        print("YES")
    else:
        print("NO")
elif C==7:
    if (A==5)and(B==5):
        print("YES")
    else:
        print("NO")
else:
    print("NO")

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

int main(){
  ll n,k;
  cin>>n>>k;
  if((n%k)*2<=k)cout<<n%k;
  else cout<<k-n%k;
  return 0;
}

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e16;

using namespace std;


int main() {
    ios::sync_with_stdio(false);

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

    ll n = 1, all = N, a = 0;
    while (n < K) {
        n *= 2;
        all *= 2;
        ++a;
    }

    ll cnt = 0;
    for (int i = 1; i <= N; ++i) {
        int j = i, k = 0;
        double t = 1.0 / N;
        while (j < K) {
            j *= 2;
            t /= 2.0;
            ++k;
        }
        ll x = 1;
        for (int j = 0; j < a - k; ++j) x *= 2;
        cnt += x;
    }

    printf("%.20lf\n", (double)cnt/all);

    return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
X = list(map(int, input().split()))
Y = [X[i+1]-X[i] for i in range(n-1)]
ans = 0
for y in Y:
    if y*a <= b:
        ans += y*a
    else:
        ans += b
print(ans)


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

#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

map<pii, int> mp;
ll H, W, N;
int ret[10];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> H >> W >> N;
    ll zero = (H - 2) * (W - 2);
    for (int i = 0, a, b; i < N; i++) {
        cin >> a >> b;
        for (int j = max(1, a - 2); j <= a && j + 2 <= H; j++) {
            for (int k = max(1, b - 2); k <= b && k + 2 <= W; k++) {
                if (mp[pii(j, k)] == 0) zero--;
                mp[pii(j, k)]++;
            }
        }
    }
    for (auto i : mp) {
        ret[i.second]++;
    }
    cout << zero << '\n';
    for (int i = 1; i < 10; i++) cout << ret[i] << '\n';
    return 0;
}

Measured memory_bytes: 56596
#include <stdio.h>
#include <string.h>

int main() {
  char c[100001];
  scanf("%s", c);
  int len = strlen(c);
  int winner;

  // printf("%d", len);

  if (len % 2 == 0) {
    if (c[0] == c[len - 1]) {
      winner = 0;
    } else {
      winner = 1;
    }
  } else {
    if (c[0] == c[len - 1]) {
      winner = 1;
    } else {
      winner = 0;
    }
  }

  if (winner == 0) {
    printf("First\n");
  } else {
    printf("Second\n");
  }

  return 0;
}

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



int main(){
    ll A,B,K;
    cin >> A >> B >> K;
    if(K<=A){
        A-=K;
    }else{
        B-=(K-A);
        A=0;
    }
    if(B<=0) B=0;
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.array;
import std.string;
import std.conv;


int main()
{
    import std.stdio;
    
    auto input = split(chomp(readln()));
    int a = to!int(input[0]);
    int b = to!int(input[1]);

    if (a <= b)
        writeln(a);
    else
        writeln(a - 1);

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
su = a[0]
gu = a[1..a.length].inject(:+)
result = (su-gu).abs
for i in 1..n-2
	su += a[i]
	gu -= a[i]
	result = (su-gu).abs < result ? (su-gu).abs : result
end
puts result


Measured memory_bytes: 16516
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
h = [int(x) for x in input().split()]
h = np.array(h,np.int64)
ans = 0
def split_(A):
    global ans
    if np.count_nonzero(A != 0) == 0:
        return
    else:
        minA = A.min()
        A -= minA
        ans += minA
        for i in range(len(A)):
            if A[i] == 0:
                split_(A[:i])
                split_(A[i+1:])
                break
split_(h)
print(ans)

Measured memory_bytes: 12404
#include <stdio.h>
#include <string.h>
int main(void){
    char str[201];
    int len,flag=0,i;
    scanf("%s",str);
    len=strlen(str);
    len--;
    if(len%2){
        len--;
    }
    while(1){
        for(i=0;i<len/2;i++){
            if(str[i]==str[len/2+i]){
                flag++;
                if(i==len/2-1){
                   printf("%d\n",flag*2);
                   return 0;
               }
            }else{
                len-=2;
                flag=0;
                i=0;
                break;
            }
        }
        if(len<1){
            break;
        }
    }
    return 0;
}


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


int main(){
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    rep(i,h) cin >> grid[i];

    rep(i,h)rep(j,w) if(grid[i][j] == '.') grid[i][j] = '0';
    int dir[3] = {1, 0, -1};

    rep(i,h){
        rep(j,w){
            if(grid[i][j] == '#'){
                rep(y,3){
                    int ny = i + dir[y];
                    if(0 <= ny && ny <= h-1){
                        rep(x,3){
                            int nx = j + dir[x];
                            if(0 <= nx && nx <= w-1){
                                if(grid[ny][nx] == '#') continue;
                                grid[ny][nx] += 1;
                            }
                        }
                    }
                }
            }
        }
    }
    for(string s : grid){
        cout << s << endl;
    }

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>

using namespace std;

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int l = Integer.parseInt(sa[2]);
		long[][] d = new long[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(d[i], 100000000000000L);
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			int c = Integer.parseInt(sa[2]);
			if (c <= l) {
				d[a][b] = c;
				d[b][a] = c;
			}
		}
		int q = Integer.parseInt(br.readLine());
		int[] s = new int[q];
		int[] t = new int[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			s[i] = Integer.parseInt(sa[0]) - 1;
			t[i] = Integer.parseInt(sa[1]) - 1;
		}
		br.close();

		int[][] ans = new int[n][n];
		long[][] ansd = new long[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(ans[i], 1000000000);
		}
		for (int i = 0; i < n; i++) {
			Set<Integer> set = new HashSet<>();
			for (int j = 0; j < n; j++) {
				set.add(j);
			}
			Node[] nodes = new Node[n];
			for (int j = 0; j < n; j++) {
				nodes[j] = new Node(j, 1000000000, 0);
			}
			TreeSet<Node> nset = new TreeSet<>();
			nset.add(nodes[i]);
			nodes[i].a = 0;
			ans[i][i] = 0;
			while (!nset.isEmpty() && !set.isEmpty()) {
				Node cur = nset.pollFirst();
				if (set.remove(cur.v)) {
					for (int j : set) {
						int alta = ans[i][cur.v];
						long c = d[cur.v][j];
						long altd = cur.d + c;
						if (altd >= 100000000000000L) {
							continue;
						}
						if (altd > l) {
							alta++;
							altd = c;
						}
						if (alta < ans[i][j]
								|| alta == ans[i][j] && altd < ansd[i][j]) {
							ans[i][j] = alta;
							ansd[i][j] = altd;
							nset.remove(nodes[j]);
							nodes[j].a = alta;
							nodes[j].d = altd;
							nset.add(nodes[j]);
						}
					}
				}
				if (nset.size() >= n) {
					throw new RuntimeException();
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			int o = ans[s[i]][t[i]];
			if (o == 1000000000) {
				pw.println(-1);
			} else {
				pw.println(o);
			}
		}
		pw.flush();
	}

	static class Node implements Comparable<Node> {
		int v;
		int a;
		long d;

		public Node(int v, int a, long d) {
			this.v = v;
			this.a = a;
			this.d = d;
		}

		public int compareTo(Node o) {
			if (a != o.a) {
				return a - o.a;
			}
			if (d != o.d) {
				return Long.compare(d, o.d);
			}
			return v - o.v;
		}
	}
}


Measured memory_bytes: 157288
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
string LCS(string s,string t){
  int sn=s.length();
  int tn=t.length();
  vector<vector<int>> dp(sn,vector<int>(tn,0));
  int flag=0;
  for(int i=0;i<sn;++i){
      if(s[i]==t[0])flag=1;
      dp[i][0]=flag;
  }
  flag=0;
  for(int i=0;i<tn;++i){
      if(s[0]==t[i])flag=1;
      dp[0][i]=flag;
  }
  for(int i=1;i<=sn-1;++i){
      rep1(j,tn-1){
          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
          if(s[i]==t[j])dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
      }
  }
  string res;
  int i=sn-1;int j=tn-1;
  while(true){
      while(j>0&&dp[i][j]==dp[i][j-1])--j;
      while(i>0&&dp[i][j]==dp[i-1][j])--i;
      if(s[i]==t[j])res+=s[i];
      if(i>0)--i;else break;
      if(j>0)--j;else break;
  }
  reverse(ALL(res));
  return res;
}
signed main(){
  string s,t;cin>>s>>t;
  cout<<LCS(s,t)<<"\n";
  return 0;
}

Measured memory_bytes: 38556
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
ll dp[2][4];
int now = 0;
int t[3];
ll p2[32];
bool use[100010];
void Threeletteracronym() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	char c[256];
	int v = 0;
	for (char i = 'a'; i <= 'z'; i++)
	{
		c[i] = 'A' + v++;
	}
	s1[0] = c[s1[0]];
	s2[0] = c[s2[0]];
	s3[0] = c[s3[0]];

	cout << s1.substr(0, 1) << s2.substr(0, 1) << s3.substr(0, 1) << endl;
}
int main() {
	Threeletteracronym();
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)

int ary[11];

bool check(int n){
  while(n){
    if(ary[n%10])n/=10;
    else return false;
  }
  return true;
}
int main(void){
  int n,l,w;
  cin>>n>>l;
  rep(i,11)ary[i] = 1;
  rep(i,l){
    cin>>w;
    ary[w] = 0;
  }
  while(n){
    if(check(n)){
      cout<<n<<endl;
      break;
    }
    n++;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
using namespace std;

typedef long long ll;

ll ans = 0;
const int MAX_N = 400;
vector<string>clr;
int H, W;
int visited[MAX_N][MAX_N];

ll numB = 0, numC = 0;

void dfs(int x, int y){
   visited[x][y] = 1;
   if(clr[x][y] == '#') numB++;
   else numC++;
   if(x+1 < H && visited[x+1][y] == 0 && clr[x][y] != clr[x+1][y]){
      dfs(x+1, y);
   }
   if(x > 0 && visited[x-1][y] == 0 && clr[x][y] != clr[x-1][y]){
      dfs(x-1, y);
   }
   if(y+1 < W && visited[x][y+1] == 0 && clr[x][y] != clr[x][y+1]){
      dfs(x, y+1);
   }
   if(y > 0 && visited[x][y-1] == 0 && clr[x][y] != clr[x][y-1]){
      dfs(x, y-1);
   }
}

int main(){
   cin >> H >> W;
   clr.resize(H);
   for(int i = 0; i < H; i++) cin >> clr[i];
   for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
         if(visited[i][j] != 1 && clr[i][j] == '#'){
            dfs(i, j);
         }
         ans += numB*numC;
         numB = 0; numC = 0;
      }
   }
   cout << ans << endl;
}



Measured memory_bytes: 23552
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

int cnt = 1;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
  seen[v] = true;
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue;
    dfs(G, next_v);  // 再帰的に探索
    cnt++;
  }
}

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // 全頂点が訪問済みになるまで探索
    int ans = 0;
    seen.assign(N, false);
    for (int v = 0; v < N; ++v) {
        cnt = 1;
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v); // v が未探索なら v を始点とした DFS を行う
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 23392
#include <bits/stdc++.h>
 
using namespace std;
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")
  
long long int x;

void solve() {
  int a = (x / 500) * 1000;
  int b = (( x % 500) / 5 ) * 5;
  cout << a + b; 
}
 
void input() {
  cin >> x;
}
 
int main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<usize>();
    }
    let mut ans = 0;
    for i in 0..n - 2 {
        let mut values = vec![seq[i], seq[i + 1], seq[i + 2]];
        values.sort();
        if seq[i + 1] == values[1] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

int main() {
  vector<int> k;
  int ans = 0;
  for(int i = 0; i < 3; ++i) {
    int a;
    cin >> a;
    k.pb(a);
    ans += a;
  }
  
  do{
    int a = k[0];
    int b = k[1];
    int c = k[2];
    int check = 0;
    check += abs(b - a);
    check += abs(c - b);
    if(ans > check) ans = check;
  } while(next_permutation(k.begin(), k.end()));

  printf("%d\n", ans);
  return 0;
}


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

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

    int n, m;
    cin >> n  >> m;

    int ans;
    ans = (n - 1) * (m - 1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  ll N, M;
  cin >> N >> M;
  ll A[N];
  rep(i, N) cin >> A[i];

  ll modsum[N+1];
  modsum[0] = 0;
  rep(i, N) modsum[i+1] = (modsum[i] + A[i]) % M;
  sort(modsum, modsum + N + 1);
  ll ans = 0, cnt = 0;
  rep(i, N){
    if(modsum[i] == modsum[i+1]){
      cnt++;
      ans += cnt;
    }
    else{
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin >> S;
    int X;
    int Xmin = 2000;
    for(int i = 0; i < S.size() - 2; i++){
        X = (S[i] - '0')*100+(S[i+1] - '0')*10+(S[i+2] - '0');
        Xmin = min(Xmin,abs(X-753));
    }
    cout << Xmin << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int H[N];
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }

    int dp[N];
    dp[0] = 0;
    dp[1] = abs(H[0] - H[1]);

    for (int i = 2; i < N; i++) {
        dp[i] = min(abs(H[i - 1] - H[i]) + dp[i - 1], abs(H[i - 2] - H[i]) + dp[i - 2]);
    }

    cout << dp[N - 1] << endl;
}

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

struct event {
    event(int u_, int x_, int b_) : u(u_), x(x_), b(b_) {}
    int u, x, b;
    bool operator<(const event& a) {
        if (u == a.u) return b < a.b;
        return u < a.u;
    }
};

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

    int n, q;
    cin >> n >> q;

    vector<int> s(n), t(n), x(n), d(q), ans(q);
    rep(i, 0, n) cin >> s[i] >> t[i] >> x[i];
    rep(i, 0, q) cin >> d[i];

    vector<event> events;
    multiset<int> z;
    z.insert(2e9);
    rep(i, 0, n) {
        events.emplace_back(s[i] - x[i], x[i], 0);
        events.emplace_back(t[i] - x[i], x[i], -1);
    }
    rep(i, 0, q) {
        events.emplace_back(d[i], i, 1);
    }
    sort(events.begin(), events.end());
    rep(i, 0, 2 * n + q) {
        if (events[i].b == -1) {
            z.erase(z.find(events[i].x));
        } else if (events[i].b == 0) {
            z.insert(events[i].x);
        } else {
            ans[events[i].x] = *z.begin();
        }
    }
    for (auto x : ans)
        if (x != 2e9)
            cout << x << endl;
        else
            cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 23528
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef long long ll;

struct A
{
  ll num;
  ll time;
  A(ll num, ll time)
	: num(num), time(time){}
};

int main()
{
  ll n, c, k;
  cin >> n >> c >> k;

  ll ans = 0;
  ll counter = 0;
  ll last_t = -1;
  bool first = true;

  vector<ll> ts(n);
  for(auto &t : ts)
  {
	cin >> t;
  }
  sort(ts.begin(), ts.end());
  
  for(auto t : ts)
  {
	if(first)
	{
	  first = false;
	  last_t = t;
	}

	if(last_t + k < t)
	{
	  counter = 1;
	  ans += 1;
	  last_t = t;
	}
	else
	{
	  counter++;
	  if(counter == c)
	  {
		counter = 0;
		ans++;
		first = true;
	  }
	}	
  }
  if(counter > 0) ans++;
  
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	int n,i,x;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		x=i;
		if(x%3==0){
			printf(" %d",i);
		}else if(x%10==3){
			printf(" %d",i);
		}else{
			while(x){
				x/=10;
				if(x%10==3){
					printf(" %d",i);
					break;
				}
			}
		}
		
		
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600