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

const int MAXN = 100010;
struct Edge {
	int to;
	Edge *next;
}*head[MAXN];
void addedge(int a, int b){
	head[a] = new Edge{b, head[a]};
}
int ans[MAXN];
bool visited[MAXN][4];
struct Node {
	int p, step, kkp;
};
int main() {
	memset(head, 0, sizeof(head));
	memset(visited, 0, sizeof(visited));
	memset(ans, 127, sizeof(ans));
	int n, m;
	cin>>n>>m;
	while(m--) {
		int a, b;
		cin>>a>>b;
		addedge(a, b);
	}
	int S, T;
	cin>>S>>T;

	//bfs
	queue<Node> que;
	que.push(Node{S, 0, 0});
	while(que.size()) {
		Node t = que.front();
		que.pop();
		if (t.step == 3) {
			ans[t.p] = min(ans[t.p], t.kkp+1);
			t.step = 0;
			t.kkp++;
		}
		if (visited[t.p][t.step])
			continue;
		visited[t.p][t.step] = true;
		for (Edge *e=head[t.p]; e; e=e->next)
			if (!visited[e->to][t.step+1]) {
				que.push(Node{e->to, t.step+1, t.kkp});
			}
	}
	if (ans[T] < 2139062000)
		cout<<ans[T]<<endl;
	else
		cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 6528
# -*- coding: utf-8 -*-

S = input()
S = S + 'R'

N = len(S)

ans = [0] * N
kids = 0
direction = 'R'
for i in range(N):
    c = S[i]

    if direction == 'R':
        if c == 'L':
            idx = i
            ans[idx - 1] += kids // 2 + kids % 2
            ans[idx] += kids // 2
            kids = 0

    elif direction == 'L':
        if c == 'R':
            ans[idx - 1] += kids // 2
            ans[idx] += kids // 2 + kids % 2
            kids = 0

    kids += 1

    direction = c

ans = ans[:-1]
print(' '.join(map(str, ans)))


Measured memory_bytes: 10980
h, w = map(int, input().split())
s = [["a"]*(w + 2)]

for i in range(h):
    s.append(list("a" + input() + "a"))
s.append(["a"]*(w + 2))

for i in range(h + 1):
    for j in range(w + 1):
        if s[i][j] == "#":
            if s[i - 1][j] != "#" and s[i][j - 1] != "#" and s[i][j + 1] != "#" and s[i + 1][j] != "#":
                print("No")
                exit()

print("Yes")

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

int main()
{
    int n;
    char ax[15];
    cin>>n;
    cin>>ax;
    int len=strlen(ax);
    if(n>=3200)
    {
        for(int i=0;i<len;i++)
        cout<<ax[i];

    }
    else cout<<"red"<<endl;
}


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

using namespace std;

int main(){
long A, B, X;
cin>>A>>B>>X;
if(A>X){
    cout<<"NO";
    return 0;
}else if(A+B>=X){
    cout<<"YES";
    return 0;
}else{
    cout<<"NO";
    }
return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    string S;
    cin >> N >> K >> S;
    string ans;
    for (int i = 0; i < N; i++) {
        if (i == K - 1) ans.push_back(char(S[i] - 'A' + 'a'));
        else ans.push_back(S[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;cin>>n;
    int a[n];rep(i,n)cin>>a[i];
    ll ans = 1000;
    ll kabu = 0;
    rep(i,n-1){
        if(a[i+1]>a[i]){
            kabu = ans/a[i];
            ans += kabu *(a[i+1] -  a[i]);
            kabu = 0;
        }
//    cout<<ans<<" " <<kabu<<endl;
    }
//    ans += kabu*a[n-1];
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

int n;

const int SIZE = 1e7 + 7;
int divis[SIZE];

void sieve(){
	for(int i = 2; i * i < SIZE; i++){
		if(divis[i] == 0)
			for(int j = i * i; j < SIZE; j += i){
				if(divis[j] == 0)
					divis[j] = i;
			}
	}
}

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

	cin >> n;
	sieve();
	for(int i = 1; i <= n; i++) if(divis[i] == 0) divis[i] = i;
	ll res = 1;
	for(ll i = 2; i <= n; i++){
		ll x = i;
		ll dziel = 1;
		int prev = -1, ile = -1;
		while(x != 1){
			if(divis[x] != prev){
				if(prev != -1) dziel *= (ile + 1);
				prev = divis[x];
				ile = 1;
			} else {
				ile++;
			}
			x /= divis[x];
		}
		dziel *= (ile + 1);
		res += dziel * i;
	}
	
	cout << res;












	
}

Measured memory_bytes: 42692
N = gets.to_i
Query = lambda{|i| # returns true/false or AC(accepted).
	puts i;
	q = {'Male'=>false, 'Female'=>true}[gets.chomp]
	if q.nil?
		puts "#{i} is Vacant."
		exit
	else
		return q
	end
}
Mid = lambda{|range|
	return range.first + range.size/2
}
Last = lambda{|range, first| # returns 順当な想定 not Vacant抜きでは矛盾する実際
	return range.size[0]==1 ? first : ! first
}

# 奇数サイズの範囲なら両端に異性を要求し(入力)、保証する(出力)。
# 偶数サイズの範囲なら両端に同性を要求し(入力)、保証する(出力)。
Step = lambda{|range, first|
	# assert(Query[range.first] == first)
	# assert(Query[range.last] == range.size[0] ? ! first : first)
	middle, last = Query[Mid[range]], ! Last[range, first]

	left = [range.first..Mid[range], first]
	right = [Mid[range]..range.last, middle]
	return left if Last[*left] != middle
	return right if Last[*right] != last
	# ここには来ない。だから２番目の return の if は本来不要。
}

$stdout.sync = true
range = 0..N-1
first, = Query[range.first], Query[range.last] # 2 queries
18.times{
	range, first = Step[range, first] # 1 query per Step
}
# No AC for 20 queries.


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

#define fto(i, a, b) for(int i = a; i <= b; ++i)
#define fdto(i, a, b) for(int i = a; i >= b; --i)
#define ff first
#define ss second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define pb push_back
#define oo 1000000007
#define OO 1000000000000000007

using namespace std;

int n, m, R;
int r[10];
int a[500][500];

int main() {
    scanf("%d%d%d", &n, &m, &R);
    fto(i, 1, R) scanf("%d", &r[i]);
    fto(i, 1, n) fto(j, 1, n) a[i][j] = oo;
    fto(i, 1, n) a[i][i] = 0;
    fto(i, 1, m) {
        int u, v, t;
        scanf("%d%d%d", &u, &v, &t);
        a[u][v] = a[v][u] = t;
    }

    fto(k, 1, n) {
        fto(u, 1, n) {
            fto(v, 1, n) {
                a[u][v] = min(a[u][k]+a[k][v], a[u][v]);
            }
        }
    }
    sort(r+1, r+1+R);
    int ans = oo;
    while (1) {
        int res = 0;
        fto(i, 1, R-1) {
            res += a[r[i]][r[i+1]];
        }
        ans = min(ans, res);
        if (!next_permutation(r+1, r+1+R)) break;
    }
    printf("%d\n", ans);
    return 0;
}
///12436


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	cout << (n+1)/2 << '\n';
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    println!("{}", (v[0] + v[1] + 1) / 2);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i=0; i<N; i++) cin >> d.at(i);
  
  int ans=N;
  for (int i=0; i<N; i++){
    for (int j=i+1; j<N; j++){
      if (d.at(i)==d.at(j)){
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
 
 
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
 
int main(){
    int t;
    cin >> t;
    int sum=0;
    for (int j=1 ; j<=t; j++){
        for (int i=1 ; i<=t; i++){
            for (int k=1 ; k<=t; k++){
                sum+= gcd(j,gcd(i,k));
            }
        }
    }
 
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
import copy

n = int(input())
arr1 = [(int(x[-1]), x) for x in list(input().split())]
arr2 = copy.copy(arr1)

def bubble_sort(arr, n):
  for i in range(n):
    for j in reversed(range(i + 1, n)):
      if arr[j][0] < arr[j-1][0]:
        arr[j], arr[j-1] = arr[j-1], arr[j]

def select_sort(arr, n):
  for i in range(n):
    minj = i
    for j in range(i, n):
      if arr[j][0] < arr[minj][0]:
        minj = j
    arr[i],arr[minj] = arr[minj],arr[i]

def check_stable(input, output):
  return 'Stable' if input == output else 'Not stable'

def arr_to_map(input):
  return ' '.join([x[1] for x in input])

bubble_sort(arr1, n)
select_sort(arr2, n)

print (arr_to_map(arr1))
print ('Stable')
print (arr_to_map(arr2))
print (check_stable(arr1, arr2))


Measured memory_bytes: 6348
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    x -= z;
    cout << x / (y + z) << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int a, b, c;

int main() {
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << 1;
  } else if (a != b && b != c && c != a) {
    cout << 3;
  } else {
    cout << 2;
  }
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
int main(){
        int a, b; cin >> a >> b;
        string q = "", w = "";
        for (int x = 0; x < a; ++x) q += '0' + b;
        for (int x = 0; x < b; ++x) w += '0' + a;
        cout << min(q, w) << endl;
    return 0;
}



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


int main() {
  int a,b,c;
  cin >> a >> b>> c;
  string out;
  if(a+b+c==17){
    if( (a==5 && b==5) || (a==5 && c==5) || (b==5 && c==5) ){
      out = "YES";
    } else{
      out = "NO";
    }
  } else{
      out = "NO";
  }
   cout << out <<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(20000000)
k = int(input())

def dfs(l, lim):
    if lim == 10:
        return l
    new_l = []
    for num in l:
        last = num % 10
        base = num * 10
        if 1 <= last <= 8:
            for i in [last-1, last, last+1]:
                if base + i <= 3234566667:
                    new_l.append(base + i)
        elif last == 0:
            for i in [0, 1]:
                if base + i <= 3234566667:
                    new_l.append(base + i)
        else:
            for i in [8, 9]:
                if base + i <= 3234566667:
                    new_l.append(base + i)
    return l + new_l + dfs(new_l, lim+1)

ans = list(set(dfs([1, 2, 3, 4, 5, 6, 7, 8, 9], 0)))
ans.sort()

print(ans[k-1])


Measured memory_bytes: 71024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)


























int main(){
    ll n, m;
    cin >> n >> m;
    priority_queue<ll, vector<ll>, greater<ll>> que;
    REP(i, n){
        ll a;
        cin >> a;
        que.push(a);
    }
    vector<pair<ll, ll>> v(m);
    REP(i, m){
        ll b, c;
        cin >> b >> c;
        v[i] = {c, b};
    }
    sort(v.begin(), v.end(), greater<pair<ll, ll>>());
    ll cnt = 0, idx;
    REP(i, m){
        cnt += v[i].second;
        idx = i;
        if(cnt > n) break;
    }
    for(ll i = idx; i >= 0; i--){
        REP(j, v[i].second){
            ll t = que.top(); que.pop();
            que.push(max(t, v[i].first));
        }
    }
    ll ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

struct pl {
    bool operator()(const pll &a, const pll &b) {
        return a.first * a.second < b.first * b.second;
    }
};

int main(void)
{
    IOS
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n),f(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> f[i];
    sort(ALL(a));
    sort(RALL(f));
    ll ng = -1, ok = a.back() * f.front();
    ll jump = ok / 2;

    auto isok = [&](ll &x){
        bool ret = true;
        ll k2 = k;
        REP(i,a.size()) {
            ll c = a[i] * f[i] - x;
            if (c > 0) {
                if (c % f[i] == 0) k2 -= c / f[i];
                else k2 -= c / f[i] + 1;
            }
            if (k2 < 0) {
                ret = false;
                break;
            }
        }
        return ret;
    };

    ll cnt = ok - jump;
    while(ng +1 < ok) {
        jump /= 2;
        if (jump == 0) jump = 1;
        if (isok(cnt)) {
            ok = cnt;
            cnt -= jump;
        } else {
            ng = cnt;
            cnt += jump;
        }
        cerr << ng << " " << ok << endl;
    }
    
    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,p,q;
   cin>>n;
   if(n%1000!=0){
     p=n/1000;
     cout<<(p+1)*1000-n<<endl;
   }
  else cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 3628
// B - Bingo
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int N;
vvi A(3,vi(3));
vi B;

auto solve(){
	rp(i,0,N)rp(r,0,3)rp(c,0,3){
		if(A[r][c] == B[i]){
			A[r][c] = 0;
			if((A[0][0]==0 && A[1][1]==0 && A[2][2] == 0)
			|| (A[0][2]==0 && A[1][1]==0 && A[2][0] == 0)
			|| (A[0][0]==0 && A[0][1]==0 && A[0][2] == 0)
			|| (A[1][0]==0 && A[1][1]==0 && A[1][2] == 0)
			|| (A[2][0]==0 && A[2][1]==0 && A[2][2] == 0)
			|| (A[0][0]==0 && A[1][0]==0 && A[2][0] == 0)
			|| (A[0][1]==0 && A[1][1]==0 && A[2][1] == 0)
			|| (A[0][2]==0 && A[1][2]==0 && A[2][2] == 0)
			){
				return "Yes";
			}
		}
	}

	return "No";
}

int main(){
	rp(i,0,3) rp(j,0,3) cin>>A[i][j];
	cin>>N;
	B.resize(N); rp(i,0,N) cin>>B[i];
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
import sys
import collections

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    B = collections.deque()

    for i, a in enumerate(A):
        if i & 1:
            B.appendleft(a)
        else:
            B.append(a)

    if N & 1:
        print(*reversed(B))
    else:
        print(*B)

    

if __name__ == '__main__':
    main()



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

int main(){
  int N,X;
  cin >> N >> X;
  int L[N];
  for(int i=0; i<N; i++){
    cin >> L[i];
  }
  int A=1;
  int D=0;
  for(int i=0; i < N; i++){
  D += L[i];
    if(D<=X){
    A++;
    }
  }
  cout << A << endl;
}
  
  
  
  

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const double EPS=1e-10;
const double PI=3.14159265358979323846;
inline int sign(double x)
{
    if(fabs(x)<=EPS)return 0;
    return x>0?1:-1;
}
struct Point{
    double x,y;
    Point(double x=0,double y=0):x(x),y(y){}
    Point operator + (Point p) { return Point(x+p.x,y+p.y); }
    Point operator - (Point p) { return Point(x-p.x,y-p.y); }
    Point operator * (double k) { return Point(k*x,k*y); }
    Point operator / (double k) { return Point(x/k,y/k); }
    inline double abs(){ return sqrt(norm()); }
    inline double norm() { return x*x+y*y; }
    bool operator < (const Point &p)const{return sign(x-p.x)<0||sign(x-p.x)==0&&sign(y-p.y)<0;}
    bool operator == (const Point & p)const{fabs(x-p.x)<EPS&&fabs(y-p.y)<EPS;}
};
typedef Point Vector;
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;}
struct Circle{
    Point c;
    double r;
    Circle(Point c = Point() ,double r = 0.0 ):c(c),r(r){}
    Point point(double a){return Point(c.x+r*cos(a),c.y+r*sin(a));}
};

int getTangents(Circle A, Circle B, Point *a, Point *b){
    int cnt = 0;       
    if(sign(A.r - B.r) < 0){swap(A, B);swap(a, b);}
    double d = sqrt((A.c.x - B.c.x) * (A.c.x - B.c.x) + (A.c.y - B.c.y) * (A.c.y - B.c.y));     
    double rdiff = A.r - B.r;     
    double rsum = A.r + B.r;    
    if(sign(d - rdiff) < 0) return 0;        
    double base = atan2(B.c.y - A.c.y, B.c.x - A.c.x);     
    if(sign(d) == 0) return -1;      
    if(sign(d - rdiff) == 0){     
        a[cnt] = b[cnt] = A.point(base);
        cnt++;
        return 1;
    }
    double ang = acos((A.r - B.r) / d);
    a[cnt] = A.point(base + ang); b[cnt] = B.point(base + ang); cnt++;     
    a[cnt] = A.point(base - ang); b[cnt] = B.point(base - ang); cnt++;   
    if(sign(d - rsum) == 0){     
        a[cnt] = b[cnt] = A.point(base);
        cnt++;
    }else if(sign(d - rsum) > 0){      
        double ang = acos((A.r + B.r) / d);
        a[cnt] = A.point(base + ang); b[cnt] = B.point(PI + base + ang); cnt++;
        a[cnt] = A.point(base - ang); b[cnt] = B.point(PI + base - ang); cnt++;
    }
    return cnt;
 
}
 
 
int main(){
    Circle A,B;
    Point a[5],b[5];
    while(scanf("%lf%lf%lf%lf%lf%lf",&A.c.x,&A.c.y,&A.r,&B.c.x,&B.c.y,&B.r)!=EOF){
        bool flag=0;
        if(sign(A.r - B.r) < 0) flag=1;
        int cnt=getTangents(A,B,a,b);
        if(cnt==-1||cnt==0) continue;
        vector<Point> v;
        for(int i=0;i<cnt;i++){
            v.push_back(a[i]);
        }
        sort(v.begin(),v.end());
        for(int i=0;i<cnt;i++){
            printf("%.10f %.10f\n",v[i].x,v[i].y);
        }
    }
    return 0;
}


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

bool chkislike( int n, int* d, int len )
{
  bool ret = true;
  string nstr = to_string( n );

  for( int i = 0; i < nstr.length(); i++ ) {
    int num = nstr[ i ] - '0';

    for( int j = 0; j < len; j++ ) {
      if( num == d[ j ] ) {
        ret = false;
        break;
      }
    }
  }

  return ret;
}

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

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

  int i;
  for( i = n; i < 100000; i++ ) {
    string nstr = to_string( i );
    bool islike = false;

    islike = chkislike( i, d, k );
    if( islike == true ) {
      break;
    }
  }

  cout << i << endl;

  return 0;
}


Measured memory_bytes: 888
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

L, R = MAP()

if R < 2019:
	li = [i for i in range(L, (R + 1))]
	co = list(combinations(li, 2))
	mi = INF
	for x in co:
		mi = min(mi, (x[0]*x[1])%2019)
	print(mi)
	exit()
if R == 2019:
	print(0)
	exit()
if R > 2019:
	if R - L < 2019:
		li = [i for i in range(L, (R + 1))]
		co = list(combinations(li, 2))
		mi = INF
		for x in co:
			mi = min(mi, (x[0]*x[1])%2019)
		print(mi)
		exit()
	else:
		print(0)
		exit()

Measured memory_bytes: 134580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size() + 1;
    vector<int> v(n, -1);
    int seq = 0;
    fori(i, 0, n) {
        v[i] = max(v[i], seq);
        if(i == n - 1) break;
        if (s[i] == '<') seq++;
        else seq = 0;
    }
    seq = 0;
    ford(i, n - 1, 0) {
        v[i] = max(v[i], seq);
        if (s[i - 1] == '>') seq++;
        else seq = 0;
    }
    ll ans = 0;
    fori(i, 0, n) {
        ans += v[i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2844
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  int n=b-a;
  if(n<1){
    cout<<"delicious"<<endl;
  }else if(n<=x){
    cout<<"safe"<<endl;
  }else{
    cout<<"dangerous"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

vll seen;
vvll to;
ll n0;
ll n1;
bool dfs(ll v) {
  bool ret = true;
  for (ll u : to[v]) {
    if (seen[u] == seen[v])
      return false;
    else if (seen[u] == -1) {
      seen[u] = 1 - seen[v];
      if (seen[u])
        n1++;
      else
        n0++;
      ret &= dfs(u);
    }
  }
  return ret;
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;

  to.resize(n);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  seen.resize(n, -1);
  seen[0] = 0;
  n0++;
  bool chk = dfs(0);
  ll ans;
  if (chk) {
    ans = n0 * n1 - m;
  } else {
    ans = n * (n - 1) / 2 - m;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7680
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
	        long valueLCM = 0;
	        ArrayList<Long> list = new ArrayList<>();
	        int n = sc.nextInt();
	        
	        for(int i=0;i<n;i++) {
	        	list.add(sc.nextLong());
	        }
	        
	        if(n==1) {
	        	System.out.println(list.get(0));
	        	return;
	        }
	        

	        for(int index=0; index<list.size()-1; index++) {
	            if( index==0 ) {
	                valueLCM = calcLCM( list.get(index), list.get(index+1) );
	            } else {
	                valueLCM = calcLCM( valueLCM,        list.get(index+1) );
	            }
	        }
	        System.out.println(valueLCM);
	    }

	    private static long calcLCM(long val1, long val2) {
	        long maxValue = Math.max(val1, val2);
	        long minValue = Math.min(val1, val2);
	        BigInteger val3 = BigInteger.valueOf(maxValue);
	        val3 = val3.multiply(BigInteger.valueOf(minValue));
	        
	        //long val3    = maxValue * minValue;

	        if(minValue==0) return maxValue;

	        long temp;
	        while( (temp=maxValue%minValue)!=0 ) {
	            maxValue=minValue;
	            minValue=temp;
	        }
	        val3 =val3.divide(BigInteger.valueOf(minValue));
	        long ret = val3.longValue();
	        
	        return ret;
	    }
		
		
	}
	


Measured memory_bytes: 36408
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		UL X; cin >> X;
		UL A[100]; rep(i, N) cin >> A[i];
		sort(A, A + N);
		UL ans = 0;
		rep(i, N - 1) {
			if (A[i] <= X) { X -= A[i]; ans++; }
		}
		if (X == A[N - 1]) ans++;
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

const int vecx[4] = { -1,0,1,0 };
const int vecy[4] = { 0,1,0,-1 };

int h, w;
char table[20][20];
bool iswalked[20][20];
int si, sj;
int ans;

void dfs(int _i, int _j) {
	ans++;
	iswalked[_i][_j] = true;
	for (int i = 0; i < 4; i++) {
		if (_i + vecx[i] >= h || _i + vecx[i] < 0 || _j + vecy[i] >= w || _j + vecy[i] < 0)continue;
		if (!iswalked[_i + vecx[i]][_j + vecy[i]] && table[_i + vecx[i]][_j + vecy[i]] == '.') {
			dfs(_i + vecx[i], _j + vecy[i]);
		}
	}
}

int main() {
	while (cin >> w >> h, w*h) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> table[i][j];
				if (table[i][j] == '@')si = i, sj = j;
			}
		}
		dfs(si, sj);
		cout << ans << endl;
		ans = 0;
		for (int i = 0; i < h; i++)for (int j = 0; j < w; j++)iswalked[i][j] = false;
	}
	return 0;
}

Measured memory_bytes: 3012
#include <stdio.h>

int main(int argc, const char * argv[]) {

    int z=-1000000,z1=1000000;
    int x,y;
    scanf("%d",&y);
    long long int sum=0;
    for(int n=1;n<=y;n++){
        scanf("%d\n",&x);

        if(z<x){
            z=x;
        }
        if(z1>x){
            z1=x;
        }
        sum+=x;
    }
    printf("%d %d %lld\n",z1,z,sum);
    return 0;
}



Measured memory_bytes: 2100
N, K = input().split()
N = int(N)
K = int(K)

kobetu_kitaiti = [(int(i) + 1)/2 for i in input().split()]

sum_ = sum(kobetu_kitaiti[0:K])
max_ = sum_

for i in range(N-K):
    sum_ = sum_ - kobetu_kitaiti[i] + kobetu_kitaiti[i+K]
    max_ = max(sum_, max_)

#print(kobetu_kitaiti)
print(max_)

Measured memory_bytes: 23588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);
 
int main(){
    IOS;
    ll n,m;cin>>n>>m;
    bool a[n][m];
    f(i,0,n){
        f(j,0,m){
            char c;cin>>c;
            a[i][j]=(c=='.');
        }
    }
    ll dx[4]={1,-1,0,0}; ll dy[4]={0,0,1,-1};
    ll ans=0;
    f(ix,0,n){
        f(iy,0,m){
            if(!a[ix][iy])continue;
            ll dist[n][m];f(i,0,n)f(j,0,m)dist[i][j]=-1;
            dist[ix][iy]=0;
            queue<ii>q;q.push({ix,iy});
            while(!q.empty()){
                ii cur=q.front();q.pop();
                ll x=cur.F,y=cur.S;
                f(i,0,4){
                        ll newx=x+dx[i];ll newy=y+dy[i];
                        if(newx<0 || newx>=n || newy<0 || newy>=m)continue;
                        if(!a[newx][newy])continue;
                        if(dist[newx][newy]!=-1)continue;
                        dist[newx][newy]=1+dist[x][y];
                        q.push({newx,newy});
                        ans=max(ans,dist[newx][newy]);
                }
            }
        }
    }
    cout<<ans;
    return 0;
}   


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

int main() {
    int64_t N;
    cin >> N;
    constexpr int64_t MOD = 1e9 + 7;

    int64_t ans = 1;
    int64_t sub1 = 1;
    int64_t sub2 = 1;
    for (int64_t _ = 0; _ < N; _++) {
        (ans *= 10) %= MOD;
        (sub1 *= 9) %= MOD;
        (sub2 *= 8) %= MOD;
    }

    (ans += MOD - sub1) %= MOD;
    (ans += MOD - sub1) %= MOD;
    (ans += sub2) %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,K;
	cin >> N >> K;
	if(N % K == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
const int MAXN=1000005,MAXM=30000000;
int P;
#define L 1048576
#define real long double
#define eps 1e-9
char _buf[L],*S,*T,_buf1[L],*S1=_buf1;
inline char gc()
{
	if(S==T)
	{
		T=(S=_buf)+fread(_buf,1,L,stdin);
		if(S==T)return 0;
	}
	return *S++;
}
template<class T> void get(T &x)
{
	char c;
	for(c=gc();(c<'0'||c>'9')&&c!='-';c=gc());
	bool b=0;
	if(c=='-')
	{
		b=1;
		c=gc();
	}
	for(x=c^'0',c=gc();c>='0'&&c<='9';c=gc())x=(x<<3)+(x<<1)+(c^'0');
	if(b)x=-x;
}
inline void pc(char c)
{
	if(S1==_buf1+L)
	{
		fwrite(_buf1,1,L,stdout);
		S1=_buf1;
	}
	*S1++=c;
}
void out(ll x)
{
	if(x>9)out(x/10);
	pc(x%10^'0');
}
int Pow(int x,int y)
{
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%P)if(y&1)s=(ll)s*x%P;
	return s;
}
int A(int x)
{
	return x<0?-x:x;
}
int n,i,j,k,ans[10005];
int main()
{
	get(n);
	for(i=1;i*i<=n;i++)for(j=1;i*i+j*j+i*j<=n;j++)for(k=1;i*i+j*j+k*k+i*j+j*k+k*i<=n;k++)ans[i*i+j*j+k*k+i*j+j*k+k*i]++;
	for(i=1;i<=n;i++)
	{
		out(ans[i]);
		pc('\n');
	}
	fwrite(_buf1,1,S1-_buf1,stdout);
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main (){
    FastIO
    lld n, r;
    cin >> n;
    cin >> r;
    if (n >= 10)
    	cout << r << "\n";
    else
    	cout << r + (100*(10-n)) << "\n";
    return 0;
}

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

int main(){

  int A, B, sum=0;
  cin >> A >> B;

  sum = A + B;

  if (sum==3){
    cout << 3 << endl;
  }

  if (sum==4){
    cout << 2 << endl;
  }

  if (sum==5){
    cout << 1 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int a[50];
signed main() {
	a[0] = 1;
	for1(i, 32)a[i] = a[i - 1] * 3;
	int t; cin >> t;
	int ans = t;
	for (int i = 32; i >= 0; i--) {
		int t1 = t - a[i] * 2 + 2;
		if (t1 < 0) continue;
		ans = 2 * i;
		for (int j = i; j >= 0; j--) while (t1 - a[j] >= 0) { t1 -= a[j]; ans++; }
		cout << ans << endl;
		return 0;
	}
}


Measured memory_bytes: 3128
'use strict';

const input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const NM = input[0].trim().split(' ');
const N = parseInt(NM[0]);
const M = parseInt(NM[1]);

console.log(
    (M <= 2 * N) ?
    Math.floor(M / 2) :
    Math.floor((2 * N + M) / 4)
);

Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define MOD 1000000007
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
	
	int n;
	cin>>n;
	int a=1,b=1,c=1;
	for(int i=1;i<=n;i++)
	{
		a=(a%MOD*10%MOD)%MOD;
		b=(b%MOD*9%MOD)%MOD;
		c=(c%MOD*8%MOD)%MOD;
	}
	//cout<<a<<" "<<b<<" "<<c<<endl;
	int ans=(a-2*b+c)%MOD;
	ans=(ans+MOD)%MOD;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3652
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pll;
typedef vector<int> vll;
typedef vector<pll> vpll;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

//

int32_t main() {
  FAST_IO;
  int a[4];
  a[3] = 0;
  rep(i, 3) {
    cin >> a[i];
    a[3] += a[i];
  }
  cout << (a[3] >= 22 ? "bust" : "win");
  rtn 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
constexpr long INF = 1L << 60;
constexpr int MOD = 1e9 + 7;

long n;
string s;

vector<pair<char, long>> RLE(string s) {
  vector<pair<char, long>> ret;
  for(int i = 0; i < (int)s.size();) {
    long cnt = 0;
    while(s[i] == s[i+cnt]) ++cnt;
    ret.emplace_back(s[i], cnt);
    i += cnt;
  }
  return ret;
}

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> s >> n;
  auto ps = RLE(s);
  long ans = 0;
  if(ps.size() == 1) {
    cout << ps[0].second * n / 2 << endl;
    return 0;
  }
  for(auto p : ps) {
    ans += p.second / 2;
  }
  if(ps[0].first == ps.back().first) {
    long l = ps[0].second;
    long r = ps.back().second;
    ans -= l / 2 + r / 2;
    ans *= n;
    ans += (l + r) / 2 * (n-1);
    ans += l / 2 + r / 2;
  } else ans *= n;
  cout << ans << endl;
  return 0;
}

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

int main(){
    int a,b,c,x;
    int res = 0;
    cin >> a >> b >> c >> x;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                res = (i*500+j*100+k*50)==x ? res+1:res;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
loop = int(input())
kokuban=[int(x) for x in input().split()]
flag=False
result =0

while(flag==False) :
    for index,obj in enumerate(kokuban) :
        if int(obj)%2 == 0:
            kokuban[index]= int(obj)//2
        else:
            flag=True
    if flag==False :
        result +=1

print(result)


Measured memory_bytes: 2940
#include<stdio.h>

void d_to_c(int d ,char c[8]){
  int i;
  int tmp = 0;
  int ten = 10000000;
  d *= d;
  for(i=0;i<8;i++){
    c[i] = (d-tmp)/ten + '0';
    tmp += (c[i] - '0')*ten;
    ten /= 10;
  }
}

int c_to_d(char c[4]){
  int i;
  int ten = 1000;
  int sum = 0;
  for(i=0;i<4;i++){
    sum += ten*(c[i] -'0');
    ten /= 10;
  }
  return sum;
}

int main(void){
  int i,j,k;
  int s;
  int n;
  char rand[8];
  char tmp[4];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s);
    printf("Case %d:\n",i+1);
    for(j=0;j<10;j++){
      d_to_c(s,rand);
      for(k=0;k<4;k++)tmp[k] = rand[k+2];
      s = c_to_d(tmp);
      printf("%d\n",s);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,m;
vector<vector<ll> > g(100005);
ll dp[100005]={0};
ll an(ll v)
{
    if(dp[v])
    return dp[v];
    //cout<<v<<'\n';
    if(g[v].size()==0)
        return 0;
    ll ans=0;
    for(auto x:g[v])
        ans=max(ans,an(x));
    dp[v]=ans+1;
    return ans+1;
}
int main()
{
    cin>>n>>m;
    pair<ll,ll> edge[m];
    bool was[n]={0};
    for(int i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        was[b]=1;
        g[a].push_back(b);
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        if(!was[i])
            ans=max(ans,an(i));
    }
    cout<<ans;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;
 
signed main(){
    ll n,m,x=-1,y=-1,ans=1;
    cin>>n>>m;
    vector<ll> fib(n+1),v;
    fib.at(0)=1;
    fib.at(1)=1;
 
    for(ll i=2;i <= n;i++)
    {
        fib.at(i)=fib.at(i-1)%mod+fib.at(i-2)%mod;
        fib.at(i)%=mod;
    }
 
    for(ll i=0;i < m;i++)
    {
        cin>>y;
        if(y==x+1){
            cout << 0 << endl;
            return 0;
        }
        v.pb(y-x-2);
        x=y;
    }
    v.pb(n-y-1);
 
    for(ll i=0;i < (ll)v.size();i++)
    {
        ans*=(fib.at(v.at(i)));
        ans%=mod;

    }
    
    cout << ans%mod << endl;
 
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int main()
{
    int n;
    cin>>n;
    int a[n+1],b[n+1],c[n];
    stack<int>s;
    int temp=0;
    for(int i=0;i<n-1;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-2;i++){
        temp+=min(a[i],a[i+1]);
    }
    cout<<temp+a[n-2]+a[0];
}


Measured memory_bytes: 256
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int x, n;
    cin >> x >> n;
    map<int, bool> st;
    for (int i = 0; i < n;i++)
    {
        int xx;
        cin >> xx;
        st[xx] = true;
    }
    int ans = -1,diff=INT_MAX;
    for (int i = 0; i <= 101;++i)
    {
        if(st.find(i)==st.end())
        {
            if(diff>abs(i-x))
            {
                diff = abs(i - x);
                ans = i;
            }
        }
    }

    cout<<ans;


#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    long double PI = 3.14159265358979;
    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    long double d1 = ((h * 60 + m) / (12.0 * 60.0)) * 2 * PI;
    long double d2 = (m / 60.0) * 2 * PI;
    long double d = abs(d1 - d2);
    chmin(d, 2 * PI - d);
    cout << fixed << setprecision(20)
         << sqrt(a * a + b * b - 2 * a * b * cos(d)) << endl;
}

Measured memory_bytes: 4156
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef long long LL;

int an,bn;LL a[110000],b[110000];
int main()
{
	int n,K;LL x;
	scanf("%d%d",&n,&K);an=0,bn=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		if(x==0)K--;
		else if(x<0)a[++an]=-x;
		else b[++bn]=x;
	}
	if(K<=0){printf("0\n");return 0;}
	for(int i=1;i<=an/2;i++)swap(a[i],a[an-i+1]);
	
	LL mmin=(1LL<<62);
	for(int i=0;i<=min(an,K);i++)
	{
		int j=K-i;
		if(j>bn)continue;
		
		mmin=min(mmin,a[i]+b[j]+min(a[i],b[j]));
	}
	printf("%lld\n",mmin);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    long x;
    cin >> x;
    int cnt_500=0;
    int cnt_5=0;
    if(x/500>=1){
        cnt_500=x/500;
        x=x-cnt_500*500;
    }
    if(x/5>=1){
        cnt_5=x/5;
    }
    cout << cnt_500*1000+cnt_5*5 << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut s = 0i64;
    let mut m = 0i64;
    for ai in a.iter().copied() {
        s += std::cmp::max(m - ai, 0);

        m = std::cmp::max(m, ai);
    }

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


Measured memory_bytes: 5592