akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
ll n;
vector<ll> d;
vector<ll> d2;
vector<bool> seen;
void dfs1(const vector<vector<ll>> &G, ll v, ll count) {
    seen[v] = true; // v を訪問済にする
    d[v] = count;
    count++;
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) {
        	continue;
        } // next_v が探索済だったらスルー
        dfs1(G, next_v, count); // 再帰的に探索
    }
}

vector<bool> seen2;
void dfs2(const vector<vector<ll>> &G, ll v, ll count) {
    seen2[v] = true; // v を訪問済にする
    d2[v] = count;
    count++;
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen2[next_v]) {
        	continue;
        } // next_v が探索済だったらスルー
        dfs2(G, next_v, count); // 再帰的に探索
    }
}
/****** define variable start ******/
vl a, b;
/******* define variable end *******/
int solve() {
	cin >> n;
	vector<vector<ll>> G(n);
	a.resize(n-1);
	b.resize(n-1);
	REP(i, n-1){
		cin >> a[i] >> b[i];
		G[a[i]-1].push_back(b[i]-1);
		G[b[i]-1].push_back(a[i]-1);
	}
	seen.resize(n);
	seen2.resize(n);
	d.resize(n);
	d2.resize(n);
	ll A = 0;
	ll B = 0;
	dfs1(G, 0, 0);

	dfs2(G, n-1, 0);

	REP(i, n){
		if(d[i] <= d2[i]){
			A++;
		}else{
			B++;
		}
	}
	if(A > B){
		cout << "Fennec" << endl;
	}else{
		cout << "Snuke" << endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

char s[1005], t[1005];

int main() {
	scanf(" %s", s);
	scanf(" %s", t);
	int lens = strlen(s);
	int lent = strlen(t);
	int maxSame = 0;
	for (int i = 0; i <= lens - lent; i++) {
		int sameCnt = lent;
		for (int j = 0; j < lent; j++) {
			if (s[i + j] != t[j]) sameCnt--;
		}
		maxSame = max(sameCnt, maxSame);
	}
	printf("%d\n", lent - maxSame);
	return 0;
}


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

int main(){
  vector<int> G[100];
  queue<int> q;
  vector<int> d(100,-1);
  int n,u,k,v,depth;
  bool flg;
  
  cin >> n;
  for (int i=0;i<n;i++){
    cin >> u>> k;
    for (int j=0;j<k;j++){
      cin >> v;
      G[u-1].push_back(v-1);
    }
  }
  depth=0;
  q.push(0);
  d[0]=depth;
  while (!q.empty()){
    u=q.front();
    for (int i=0;i<G[u].size();i++){
      v=G[u][i];
      if (d[v]==-1){
	q.push(v);
	d[v]=d[u]+1;
	flg=true;
	break;
      }
    }
    if (!flg){
      q.pop();
    }else{
      flg=false;
    }
  }
    
  for (int i=0;i<n;i++)
    cout << i+1 <<" "<< d[i]<<endl;
  
  return 0;
}

Measured memory_bytes: 3116
from collections import defaultdict

H, W, M = map(int, input().split())

h = [-1]
w = [-1]
hw_dict = defaultdict(int)

for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)

for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []

for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        if hw_dict[(i, j)] == 0:
            print(h_max + w_max)
            exit()

print(h_max + w_max - 1)


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

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

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  ll x, y;
  cin >> x >> y;
  cout << (abs(x - y) > 1 ? "Alice" : "Brown") << endl;
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#define dprintf(...) printf(__VA_ARGS__)
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#define dprintf(...)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;
using namespace atcoder;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

template <class T>
vec2<T> vec2_init(int n0, int n1, T x = 0) {
    return vec2<T>(n0, vector<T>(n1, x));
}

template <class T>
vec3<T> vec3_init(int n0, int n1, int n2, T x = 0) {
    return vec3<T>(n0, vec2_init(n1, n2, x));
}

/*
 *           U P
 *           - x
 *            ^
 *            |
 * LEFT -y <--+--> +y RIGHT
 *            |
 *            v
 *           + x
 *         D O W N
 */

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

enum {
    DOWN,
    RIGHT,
    UP,
    LEFT,
};

constexpr double inf = numeric_limits<double>::infinity();

int op(int x, int y) {
    return max(x, y);
}

int e() {
    return 0;
}

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

    constexpr int A_MAX = 300000;

    int N, K;
    cin >> N >> K;
    segtree<int, op, e> st(A_MAX + 1);
    REP(i, N) {
        int A;
        cin >> A;
        int l = max(A - K, 0);
        int r = min(A + K, A_MAX);
        int x = st.prod(l, r + 1);
        st.set(A, x + 1);
    }
    int result = st.all_prod();
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 8424
# D - String Formation
s = input()
q = int(input())

f = ''
b = ''
odd = 0
for i in range(q):
    t,*fc = input().split()
    if t=='1': odd ^= 1 #t1
    else: #t2
        if odd ^ (int(fc[0])-1): b += fc[1]
        else: f += fc[1]

if odd: print(b[::-1] + s[::-1] + f)
else: print(f[::-1] + s + b)

Measured memory_bytes: 4340
import java.util.Scanner;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    String str = sc.nextLine();
	    str = getStr(str.toCharArray(), str.length());
	    String[] stt = new String[1024];
	    int p = 0;

	    for(int i = str.length(); i > 2; i--){
		for(int j = 0; j+i <= str.length(); j++){
		    String str2 = str.substring(j, j+i);
		    char[] ch = str2.toCharArray();
		    boolean f = true;
		    for(int s = 0, t = str2.length()-1; s < t; s++, t--){
			if(ch[s] != ch[t]){
			    f = false;
			    break;
			}
		    }
		    if(f){
			for(int k = 0; k < p; k++){
			    int l1 = stt[k].length(), l2 = str2.length();
			    if(l1%2 == l2%2){
				if(l1 > l2){
				    l1 = (l1-l2)/2;
				    if(str2.equals(stt[k].substring(l1, l1+l2))){
					f = false;
					break;
				    }
				} else if(l1 == l2){
				    if(str2.equals(stt[k])){
					f = false;
					break;
				    }
				}
			    }
			}
			if(f){
			    stt[p++] = str2;
			}
		    }
		}
	    }

	    if(p > 0){
		System.out.print(stt[0]);
		for(int i = 1; i < p; i++){
		    System.out.print(" "+stt[i]);
		}
	    }
	    System.out.println();
	}
    }

    String getStr(char[] ch, int n){
	String str="";
	for(int i = 0; i < n; i++){
	    if((ch[i] >= 'a' && ch[i] <= 'z')||(ch[i] >= 'A' && ch[i] <= 'Z')){
		str += ch[i];
	    }
	}

	return str.toUpperCase();
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 12000
use std::ops::Sub;
use std::ops::Div;
use std::ops::Mul;
use std::ops::Rem;
use std::ops::ShrAssign;
use std::ops::BitAnd;
use std::cmp::min;

const MOD: i64 = 1000000007;


fn main() {
    let (n, a, b) = read_tuple::<i64>();

    let r = min(n as usize, 2e5 as usize) + 1;
    let m = MOD;
    let mut finv = Vec::with_capacity(r);
    finv.push(1);
    finv.push(1);
    let mut inv = Vec::with_capacity(r);
    inv.push(1);
    inv.push(1);
    for i in 2..r {
        let i = i as i64;
        let tmp = m - inv[(m % i) as usize] * (m / i) % m;
        inv.push(tmp);
        let tmp = finv.last().unwrap() * inv.last().unwrap() % m;
        finv.push(tmp);
    }


    let total: i64 = modpow(2, n, MOD) - 1;

    let nca = {
        let a = min(a, n-a);
        let mut tmp = 1;
        for i in (n-a+1)..(n + 1) {
            tmp *= i;
            tmp %= MOD;
        }
        tmp *= finv[a as usize];
        tmp %= MOD;
        tmp
    };

    let ncb = {
        let b = min(b, n-b);
        let mut tmp = 1;
        for i in (n-b+1)..(n + 1) {
            tmp *= i;
            tmp %= MOD;
        }
        tmp *= finv[b as usize];
        tmp %= MOD;
        tmp
    };

    let mut ans = total - nca;
    if ans < 0 {
        ans += MOD;
    }
    ans -= ncb;
    if ans < 0 {
        ans += MOD;
    }
    

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


pub fn modpow<T>(mut a: T, mut n: T, m: T) -> T
    where T: Sub<Output=T> + Div<Output=T> + Mul<Output=T> + Rem<Output=T> + ShrAssign + PartialOrd + BitAnd<Output=T> + Copy + From<u8>
{
    let zero = T::from(0);
    let one = T::from(1);
    let mut res = one;

    while n > zero {
        if (n & one) == one {
            res = res * a % m;
        }
        a = a * a % m;
        n >>= one;
    }

    res
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T, T) {
    let temp = read_vec();
    (temp[0], temp[1], temp[2])
}



Measured memory_bytes: 8444
#include<iostream>
using namespace std;
#define int long long
#define mod 998244353
int L[11],R[11];
int dp[200005];
int sum[200005];

signed main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int N,K;
	cin >> N >> K;
	for(int i = 1; i <= K; i++)
	{
		cin >> L[i] >> R[i];
	}
	sum[1] = dp[1] = 1;
	for(int i = 2; i <= N; i++)
	{
		for(int j = 1; j <= K; j++)
		{
			if(i - L[j] < 1)
			continue;
			else if(i- R[j] < 1)
			{
				dp[i] = (dp[i] + sum[i-L[j]])%mod;
			}
			else
			{
				dp[i] = (dp[i] + sum[i-L[j]])%mod;
				dp[i] = (dp[i] - sum[i-R[j]-1] + mod)%mod;
			}
		}
		sum[i] = (sum[i-1] + dp[i])%mod;
	}
	cout << dp[N] << endl;
}

Measured memory_bytes: 6280
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

string s;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> s;
   if (s == "SUN") cout << 7;
   if (s == "MON") cout << 6;
   if (s == "TUE") cout << 5;
   if (s == "WED") cout << 4;
   if (s == "THU") cout << 3;
   if (s == "FRI") cout << 2;
   if (s == "SAT") cout << 1;
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){

    int s;
    cin>>s;

    char N[s];
    cin>>N;

    int count =0;
    for(int i=0;i<s;i++){
        if(N[i]=='A' && N[i+1]=='B' && N[i+2]=='C'){
            count++;
            i = i+2;
        }
        else{
            continue;
        }
    }

    cout<<count<<endl;

    return 0;
}





Measured memory_bytes: 256
stdin.ReadLine()
|> fun x -> x.Split(' ')
|> Array.map int64
|> fun x -> (x.[0], x.[1], x.[2])
|> fun (a, b, x) ->
    (b / x) - if a = 0L then -1L else ((a - 1L) / x)
    |> printfn "%d"


Measured memory_bytes: 14040
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func SliceAtoi(sa []string) ([]int, error) {
	si := make([]int, 0, len(sa))
	for _, a := range sa {
		i, err := strconv.Atoi(a)
		if err != nil {
			return si, err
		}
		si = append(si, i)
	}
	return si, nil
}

func StdInNumSlice() []int {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	stringInput := scanner.Text()
	A, _ := SliceAtoi(strings.Split(stringInput, " "))
	return A
}

func main() {
	A := StdInNumSlice()
	a := A[0] * A[1]
	s := A[0]*2 + A[1]*2
	fmt.Printf("%v %v\n", a, s)
}



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


int main(){
    ll n;
    cin>>n;
    ll ans;

    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    else{
        ans = (n)*(n-1)/2;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define abs(x) (x>0?x:-(x))
#define MAX(x,y) (x>y?x:y)
#define D 200
#define N 200
#define INF 1000000
using namespace std;

typedef struct{
	int max_t,min_t,c;
} clothes;

int main(){
	clothes clt[N];
	int t[D];
	int d,n;
	cin>>d>>n;

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

	for(int i=0;i<n;i++){
		cin>>clt[i].min_t>>clt[i].max_t>>clt[i].c;
	}

	int dp[D][N];
	
	for(int i=0;i<d;i++){
		for(int j=0;j<n;j++){
			if(i==0 && clt[j].min_t<=t[0] && clt[j].max_t>=t[0]) dp[i][j]=0;
			else dp[i][j]=-INF;
		}
	}

	for(int i=1;i<d;i++){
		for(int j=0;j<n;j++){
			if(clt[j].min_t<=t[i] && clt[j].max_t>=t[i]){
				for(int k=0;k<n;k++){
					dp[i][j]=MAX(dp[i][j],dp[i-1][k]+abs(clt[k].c-clt[j].c));
				}
			}
		}
	}
	
	int m=0;
	for(int i=0;i<n;i++){
		m=MAX(m,dp[d-1][i]);
	}

	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 1316
#include<stdio.h>
int main(void)
{
  int abc[3],str[3],i,j,delete,count=0;
  scanf("%d%d%d",&abc[0],&abc[1],&abc[2]);
  for(i=0; i<3; i++)
  {
    str[i]=0;
    for(j=0; j<3; j++)
    {
      if(str[i]<abc[j])
      {
        str[i]=abc[j];
        delete=j;
      }
    }
    abc[delete]=0;
  }
  if(str[1]%2 == str[2]%2)
  {
    while(str[1]>str[2])
    {
      str[2]=str[2]+2;
      count++;
    }
    while(str[0]>str[1])
    {
      str[1]++;
      count++;
    }
  }
  else
  {
    str[0]++;
    str[1]++;
    count++;
    while(str[1]>str[2])
    {
      str[2]=str[2]+2;
      count++;
    }
    while(str[0]>str[1])
    {
      str[1]++;
      count++;
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,k,dp[100005],a[105];
ll f(ll k)
{
    if(dp[k]!=-1)
        return dp[k];
    ll ans=0;
    rep(i,0,n)
    {
        if(k-a[i]<0)
            break;
        if(f(k-a[i])==0)
        {
            ans=1;
            break;
        }
    }
    dp[k]=ans;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    rep(i,0,n)
    cin>>a[i];
    memset(dp,-1,sizeof(dp));
    if(f(k)==1)
        cout<<"First\n";
    else
        cout<<"Second\n";
}


Measured memory_bytes: 7500
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def problem(s):
    size = len(s)

    evens = s[::2]
    odds = s[1::2]

    p1 = size - (evens.count('0') + odds.count('1'))
    p2 = size - (evens.count('1') + odds.count('0'))

    return min(p1, p2)


def main():
    s = input()

    print(problem(s))


if __name__ == '__main__':
    main()


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

#define ll              long long int
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x


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

    vector<int> v(n);

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

    vector<int> dp(n, 0);

    dp[n-1] = 0;
    dp[n-2] = abs(v[n-2]-v[n-1]);

    for(int i=n-3; i>=0; i--){
        int op1 = dp[i+1] + abs(v[i+1]-v[i]);
        int op2 = dp[i+2] + abs(v[i+2]-v[i]);

        dp[i] = min(op1, op2);
    }
    
    cout<<dp[0]<<"\n";

    return 0;
}

Measured memory_bytes: 1024
from collections import Counter
N = int(input())
A = [int(input()) for i in range(N)]
sortA = sorted(A)
maxA = sortA[-1]
count_a = Counter(A)
if count_a[maxA] >= 2:
    for i in range(N):
        print(maxA)
elif count_a[maxA] == 1:
    for a in A:
        if a == maxA:
            print(sortA[-2])
        else:
            print(maxA)


Measured memory_bytes: 74324
def c166(n, m, hl, abli):

    flag = [True]*n

    for i in abli:
        if hl[i[0]-1] < hl[i[1]-1]:
            flag[i[0]-1] = False
        elif  hl[i[0]-1] == hl[i[1]-1]:
            flag[i[0]-1] = False
            flag[i[1]-1] = False
        else:
            flag[i[1]-1] = False

    ans = flag.count(True)
    return ans

def main():
    n, m = map(int, input().split())
    hl = list(map(int, input().split()))
    abli = [list(map(int, input().split()))for i in range(m)]
    print(c166(n, m, hl, abli))

if __name__ == '__main__':
    main()

Measured memory_bytes: 93232
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll A, B, C;
	cin >> A >> B >> C;

	if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
		cout << 0;
		return 0;
	}
	else if (A == B && B == C) {
		cout << -1;
		return 0;
	}

	for (int i = 0; i < 10000; i++) {

		ll tA = A;
		ll tB = B;
		ll tC = C;

		A = (tB + tC) / 2;
		B = (tC + tA) / 2;
		C = (tA + tB) / 2;

		if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
			cout << i+1;
			return 0;
		}
	}
	cout << -1;

}


Measured memory_bytes: 256
n= int(input())
s = input()

half= int(len(s)/2)

if len(s)%2 == 1 :
    print('No')
    exit(0)
else:
    for i in range(half):
        if s[i]!=s[i+half]:
            print('No')
            exit(0)
        else:
            pass
print('Yes')

Measured memory_bytes: 3060
#include<iostream>
#include<vector>

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A;
  int a;
  for(int i = 0; i < N; i++) {
    cin >> a;
    A.push_back(a);
  }
  int sum = 0;
  for(int k = 0; k < N; ++k) {
    sum += A[k];
  }
  int ave = sum / N;
  if(((ave + 1) * N - sum) < (sum - ave * N)) {
    ++ave;
  }
  int result = 0;
  for(int l = 0; l < N; ++l) {
    result += (ave - A[l]) * (ave - A[l]);
  }
  cout << result << endl;;
  return 0;
}


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

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

    int min1, min2;
    min1 = H1 * 60 + M1;
    min2 = H2 * 60 + M2;

    int ans = min2 - min1 - K;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll inf=1000000007;
const ll maxinput=3005;
const ll mod=998244353;
#define mp make_pair
ll n,a[maxinput];
pair <ll,ll> dp[maxinput][maxinput][2];
pair <ll,ll> optplay(ll i,ll j,ll player)
{
    if(i>j)
        return(mp(0,0));

    if(dp[i][j][player].first!=-1&&dp[i][j][player].second!=-1)
        return(dp[i][j][player]);
    if(player==0)
    {
        //return(max(a[i]+optplay(i+1,j,1),a[j]+optplay(i,j-1,1)));
        pair <ll,ll> temp1,temp2;
     
        temp1=optplay(i+1,j,1); temp2=optplay(i,j-1,1);
        if(a[i]+temp1.first-temp1.second>a[j]+temp2.first-temp2.second)
            return(dp[i][j][player]=mp(a[i]+temp1.first,temp1.second));
        else
            return(dp[i][j][player]=mp(a[j]+temp2.first,temp2.second));
    }
    else
    {
        pair <ll,ll> temp1,temp2;
     
        temp1=optplay(i+1,j,0); temp2=optplay(i,j-1,0);
        if(temp1.first-a[i]-temp1.second<temp2.first-a[j]-temp2.second)
            return(dp[i][j][player]=mp(temp1.first,a[i]+temp1.second));
        else
            return(dp[i][j][player]=mp(temp2.first,a[j]+temp2.second));
    }
}
int main()
{
    for(int i=0;i<maxinput;i++)
        for(int j=0;j<maxinput;j++)
            dp[i][j][0]=mp(-1,-1),dp[i][j][1]=mp(-1,-1);

    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    
    pair <ll,ll> xy=optplay(0,n-1,0); //optplay[i][j] is the result of play when the ends are i,j and 0 if its taro's turn and 1 if its jiro
    cout<<xy.first-xy.second<<"\n";

}

Measured memory_bytes: 282624
int_n, int_m = map(int, input().split())

li_a = list()
li_b = list()

for i in range(int_n):
    li_a.append(input())

for i in range(int_m):
    li_b.append(input())


for x in range(int_n - int_m + 1):
    for y in range(int_n - int_m + 1):
        li_w = [a[0 + x: int_m + x] for a in li_a[0 + y: int_m + y]]
        if "".join(li_w) == "".join(li_b):
            print("Yes")
            exit(0)
else:
    print("No")

Measured memory_bytes: 3064
S = input()

count = 0
max_count = 0
for i in S:
    if i in ('A', 'T', 'C', 'G'):
        count += 1
    else:
        if count > max_count:
            max_count = count
        count = 0

if count > max_count:
    max_count = count

print(max_count)

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}



int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(int argc, char const* argv[])
{
    string s;
    cin >> s;

    string ops;
    int total;
    for (int i = 0; i < (1 << 3); i++) {
        int t=i;
        total=ctoi(s[0]);
        ops="";
        for (int j = 1; j <= 3; j++) {
            if (t & 1) {
                total += ctoi(s[j]);
                ops += "+";
            }else{
                total -= ctoi(s[j]);
                ops += "-";
            }
            t /= 2;
        }
        if (total == 7) {
            break;
        }
    }

    for (int i = 0; i < 3; i++) {
        cout << s[i] << ops[i];
    }
    cout << s[3] << "=7" << endl;

    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector


// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc081/tasks/arc086_a



N, K = gets.split.map(&:to_i)
As = gets.chomp.split

num_counts = As.each_with_object(Hash.new(0)) { |s, hash| hash[s] += 1 }

diff = num_counts.size - K
if diff <= 0
  puts 0
  exit
end

ans = 0
num_counts.sort { |a, b| a[1] <=> b[1] }.each do |num, count|
  if diff <= 0
    break
  end
  ans += count
  diff -= 1
end

puts ans


Measured memory_bytes: 48624
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fill(x,c) memset(x,c,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int SIZE = 1e6+10;
const int Max = 1e6 + 10;
ll a[SIZE];
ll fact[Max], ifact[Max];		//fact[i]是i的阶乘,ifact[i]是阶乘的除法逆元，两者用于求组合数
ll pow_mod(ll n, ll k)
{
	ll res = 1;
	n = n % mod;
	while (k > 0)
	{
		if (k & 1)
			res = res * n % mod;
		n = n * n % mod;
		k >>= 1;
	}
	return res;
}
 
void init()		//初始化
{
	fact[0] = ifact[0] = 1;
	for (int i = 1;i < Max; i++)
	{
		fact[i] = (fact[i - 1] * i) % mod;
		ifact[i] = pow_mod(fact[i], mod - 2);
	}
}
 
ll C(ll n, ll m)
{
	if (n < m || m < 0) return 0;		//不合法
	return (fact[n] * ifact[m] % mod) * ifact[n - m] % mod;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n,k,ans=0;
	cin>>n>>k;
	if(k==1)return cout<<0,0;
	init();
	rep(i,0,n)cin>>a[i];
	sort(a,a+n);
	
	for(int i=0;i<n-k+1;i++){
		ans-=a[i]*C(n-i-1,k-1);
		ans%=mod;
	}
	
	for(int i=k-1;i<n;i++){
		ans+=a[i]*C(i,k-1);
		ans%=mod;
	}
	
	cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 18688
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    s=input()
    for i,a in enumerate(s):
        if a=='A':
            break
    for j in range(len(s)-1,-1,-1):
        if s[j]=='Z':
            break
    print(j-i+1)
        
if __name__ == '__main__':
    main()


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

using namespace std;

const int Mod = 1e9 + 7, Nmax = 1e6 + 5;
typedef long long ll;

int inm(int x, int y, int z=1) { return (ll)x*y%Mod*z%Mod; }
void inm_to(int &x, int y) { x = (ll)x*y%Mod; }
void add_to(int &x, int y) { x+=y; if(x>=Mod) x-=Mod; }

int fact[Nmax], ifact[Nmax], dp[Nmax];
int n, i;


int power(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b&1) inm_to(ans, a);
        inm_to(a, a); b >>= 1;
    }
    return ans;
}

int comb(int n, int k)
{
    if(n < 0 || n < k || k < 0) return 0;
    return inm(fact[n], ifact[k], ifact[n-k]);
}

int main()
{
 //   freopen("input", "r", stdin);

    cin >> n;

    fact[0] = ifact[0] = 1;
    for(i=1; i<=n; ++i) fact[i] = inm(fact[i-1], i);
    ifact[n] = power(fact[n], Mod-2);
    for(i=n-1; i; --i) ifact[i] = inm(ifact[i+1], i+1);

    for(i=1; i<n; ++i)
    {
        dp[i] = comb(i-1, 2*i-n);
        inm_to(dp[i], inm(fact[i], fact[n-i-1]));
    }


    for(i=n-1; i; --i)
        add_to(dp[i], Mod - dp[i-1]);

    int ans = 0;
    for(i=1; i<n; ++i)
        add_to(ans, inm(dp[i], i));

    cout << ans << '\n';
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N-1);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    a.at(i) = a.at(i) - 1;
  }
  for(int j = 0; j < N; j++){
    cin >> b.at(j);
  }
  for(int k = 0; k < N-1; k++){
    cin >> c.at(k);
  }
  
  int p = b.at(a.at(0));
  
  for(int l = 1; l < N; l++){
    p += b.at(a.at(l));
    if(a.at(l-1) + 1 == a.at(l)){
      p += c.at(a.at(l)-1);
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,W;
    ll w[101];
    ll v[101];
    ll w_first = 0;
    std::cin >> n>>W;
    for (int i = 0; i < n; i++) {
        std::cin >> w[i]>>v[i];
        if(i==0){
            w_first = w[0];
        }
        w[i] -= w_first;
    }
    ll dp[101][101][400];
    Fill(dp,0);
    
    for (int i = 0; i < n; i++) {
        for (int k = 1; k <= n; k++) {
            for (int t = 0; t <= 3*n; t++) {
                if(i>0){
                    dp[i][k][t] = dp[i-1][k][t];
                }
                if(i>0 && t-w[i]>=0){
                    dp[i][k][t] = max( dp[i][k][t], dp[i-1][k-1][t-w[i]] + v[i] );
                }else if( t-w[i]>=0){
                    dp[i][k][t] = v[i];
                }
            }
        }
    }
    ll result = 0;
    
    for (int k = 1; k <= n; k++) {
        for (int t = 0; t <= 3*n; t++) {
            if(k*w_first + t<=W){
                result = max(result,dp[n-1][k][t]);
            }
        }
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 32128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a1 = 0;
  int a2 = 0;
  int a3 = 0;
  int sum = 0;
  
  cin >> a1;
  cin >> a2;
  cin >> a3;
  
  sum = a1 + a2 + a3;
  
  if (sum >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  umll D;
  REP(i, 0, N) {
    ll d;
    cin >> d;
    if (D.find(d) != D.end()) {
      D[d] += 1;
    } else {
      D.emplace(d, 1);
    }
  }
  ll M;
  cin >> M;
  vll T(M);
  REP(i, 0, M) {
    cin >> T[i];
  }

  REP(i, 0, M) {
    if (D.find(T[i]) == D.end()) {
      cout << "NO" << endl;
      return 0;
    }

    if (D[T[i]] == 0) {
      cout << "NO" << endl;
      return 0;
    }

    D[T[i]]--;
  }
  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 10056
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int mod;
inline int ad(int x){return x>=mod?x-mod:x;}
int f[6010][2010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),ans=0;mod=read();
    f[0][0]=1;
    for(int i=0;i<n*3;i++)
    {
    	for(int j=0;j<=n;j++)
    	{
	    	for(int k=1;k<=3;k++)
	    	{
	    		int uf=j+1,ul=1;
	    		if(k==1)uf--;
	    		else
				{
					ul=1LL*ul*(i+k-1)%mod;
					if(k==3)ul=1LL*ul*(i+k-2)%mod;
				}
	    		if(uf>n)continue;
	    		f[i+k][uf]=ad(f[i+k][uf]+1LL*f[i][j]*ul%mod);
	    	}
	    }
    }
	for(int i=0;i<=n;i++)ans=ad(ans+f[n*3][i]);
	pr2(ans);
    return 0;
}

Measured memory_bytes: 47232
import sys
input = sys.stdin.readline
from collections import *

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9+7
p, n = [], []

for Ai in A:
    if Ai>=0:
        p.append(Ai)
    else:
        n.append(Ai)

if len(p)==0 and K%2==1:
    if 0 in A:
        print(0)
    else:
        n.sort(reverse=True)
        ans = 1
        
        for ni in n[:K]:
            ans *= ni
            ans %= MOD
        
        print(ans)
    exit()
    
if K==N:
    ans = 1
    
    for Ai in A:
        ans *= Ai
        ans %= MOD
    
    print(ans)
    exit()

p.sort(reverse=True)
n.sort()

if K%2==0:
    l = []
    
    for i in range(len(p)//2):
        l.append(p[2*i]*p[2*i+1])
    
    for i in range(len(n)//2):
        l.append(n[2*i]*n[2*i+1])

    l.sort(key=lambda x: abs(x), reverse=True)
    ans = 1
    
    for i in range(K//2):
        ans *= l[i]
        ans %= MOD
else:
    ans = p[0]
    p = p[1:]
    l = []
    
    for i in range(len(p)//2):
        l.append(p[2*i]*p[2*i+1])
    
    for i in range(len(n)//2):
        l.append(n[2*i]*n[2*i+1])
    
    l.sort(key=lambda x: abs(x), reverse=True)
    
    for i in range((K-1)//2):
        ans *= l[i]
        ans %= MOD

print(ans)


Measured memory_bytes: 113004
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdexcept>
#include<cmath>
#include<fstream>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define S second
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

int main(){

  int e;
  while(true){
    cin >> e;
    if(!e)break;
    int x,y,z,mine;
    mine = INF;
    for(int i=0;i<=sqrt(e)+1;i++){
      for(int j=0;j<=100;j++){
	if(pow((double)j,3) > e)break;
	y = pow((double)i,2);
	if(y > e)break;
	z = pow((double)j,3);
	if(y+z > e)break;
	x = e - (y+z);
	if(x+i+j < mine)mine = x+i+j;
      }
    }

    cout << mine << endl;
  }
return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

int n;
int k;
set<int> f;
set<int> all;

void back( int pos, int cur ) {
	if (pos == 6) return;
	all.insert(cur);
	for (auto i : f) {
		back(pos + 1, cur*10 + i);
	}
} 

signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;
	for (int i = 0; i <= 9; i++) {
		f.insert(i);
	}
	int x;
	for (int i = 1; i <= k; i++) {
		cin >> x;
		f.erase(x);
	}
	for (auto i : f) {
		back(1, i);
	}
	cout << *all.lower_bound(n);
}

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

int main()
{
  int h, n;
  cin >> h >> n;
  long long total=0;
  for (int i=0; i<n; i++)
  {
    int a;
    cin >> a;
    total += a;
  }

  cout << ( (total >= h) ? "Yes" : "No" ) << endl;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int a, b;
    cin >> a >> b;

    int ans = -1;
    ans = max(ans, a+(a-1));
    ans = max(ans, a+b);
    ans = max(ans, b+(b-1));
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n) {
        cin >> x.at(i);
    }
    sort(x.begin(), x.end());
    int ans = INT_MAX;
    for(int i = x[0]; i < x[n - 1] + 1; i++) {
        int sum = 0;
        for(int j=0; j<n; j++) {
            sum += (x[j] - i) * (x[j] - i);
        }
        if(sum < ans) {
            ans = sum;
        }
    }
    cout << ans << endl;
    return 0;
}



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

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

    vector<int> part_min(N,0);
    part_min[0]=P[0];
    for(int i=1;i<N;i++){
        part_min[i] = min(part_min[i-1],P[i]);
    }

    int cnt=1;

    for(int i=1;i<N;i++){
        if(part_min[i-1]>=P[i])cnt++;
    }

    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(void)
{
	int x;
	int i;
	
	i = 0;
	
	while(1){
		scanf("%d", &x);
		if(x == 0){
			break;
		}
		i++;
		printf("Case %d: %d\n",i, x);
	}
	
	return (0);
}

Measured memory_bytes: 600
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[][] nums = new int[h][w];
        int[][] ans = new int[h * w][4];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                nums[i][j] = sc.nextInt();
            }
        }
        int size = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w - 1; j++) {
                if (nums[i][j] % 2 == 1) {
                    nums[i][j]--;
                    nums[i][j + 1]++;
                    int[] tmp = {i, j, i, j + 1};
                    for (int k = 0; k < 4; k++) {
                        ans[size] = tmp;
                    }
                    size++;
                }
            }
        }
        for (int i = 0; i < h - 1; i++) {
            if (nums[i][w - 1] % 2 == 1) {
                nums[i][w - 1]--;
                nums[i + 1][w - 1]++;
                int[] tmp = {i, w - 1, i + 1, w - 1};
                for (int k = 0; k < 4; k++) {
                    ans[size] = tmp;
                }
                size++;
            }
        }

        System.out.println(size);
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print((ans[i][j]+1)+" ");
            }
            System.out.println(ans[i][3] + 1);
        }

    }
}


Measured memory_bytes: 109924
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int n,k,s=0;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    sort(h.rbegin(),h.rend());
    if(k>=n)
    {
        cout<<0;
    }
    else
    {
        for(int i=k;i<n;i++)
        {
            s+=h[i];
        }
        cout<<s;
    }
}

Measured memory_bytes: 1792
#include <iostream> 
#include <string>
#include <vector>

using namespace std;
int main() {
    int n, maxValue = 0, count = 0;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[n];
        if (h[n] >= maxValue) {
            maxValue = h[n];
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
#define MAXN 1000

using namespace std;

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

void solve(){
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
}

int main(){
    // int t;
    // scanf("%d", &t);
    // while(t--){
    //     solve();
    // }

    solve();
    return 0;
}

Measured memory_bytes: 256
import itertools

n = int(input())
towns = [tuple(map(int, input().split())) for _ in range(n)]

def calc(i, j):
    return ((towns[i][0] - towns[j][0])**2 + (towns[i][1] - towns[j][1])**2)**0.5

l = list(range(n))
p = list(itertools.permutations(l, n))

total = 0
for p_ in p:
    for i in range(n-1):
        total += calc(p_[i], p_[i+1])

res = total / len(p)

print(res)

Measured memory_bytes: 8052
import java.util.*;


public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 0;
        int secondMax = 0;
        List<Integer> list = new ArrayList<>();
        for(int tmp = 0; tmp < n ; tmp++){
            int a = sc.nextInt();
            list.add(a);
            if(max < a){
                max = a;
            }else {
                if (secondMax < a) {
                    secondMax = a;
                }
            }
        }
        for(int tmp =0; tmp < n; tmp++){
            int b = list.get(tmp);
            if(b == max){
                System.out.println(secondMax);
            }else{
                System.out.println(max);
            }
        }
    }
}


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

int main()
{
	int debt = 100000;
	int n;
	cin >> n;

	for(int i=0; i<n; ++i)
	{
		int x = debt * 1.05 + 999;
		debt = x - x%1000;
	}

	cout << debt << '\n';
}

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

int main(){
  string s;
  int ans;
  cin >> s;
  if(s[0] == '1')
    ans++;
  if(s[1] == '1')
    ans++;
  if(s[2] == '1')
    ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

struct union_find{//1-origin
	vector<int> rnk, par;
	
	union_find(int n) {
		rnk.resize(n+1);
		par.resize(n+1);
		for(int i = 1; i <= n; i++){
			par[i] = i;
			rnk[i] = 0;
		}
	}
	
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}
 
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rnk[x] < rnk[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rnk[x] == rnk[y])rnk[x]++;
		}
	}
	
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
};


int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, m, k, c, d;
	cin >> n >> m >> k;
	union_find uf(n);
	ll a[m], b[m];
	
	zep(i, 0, m){
		cin >> a[i] >> b[i];
		uf.unite(a[i], b[i]);
	}
	
	ll ans[n+1];
	memset(ans, 0, sizeof(ans));
	rep(i, 1, n){
		if(i != uf.find(i)){
			ans[uf.find(i)]++;
		}
	}
	
	rep(i, 1, n){
		ans[i] = ans[uf.find(i)];
	}
	
	zep(i, 0, m){
		if(uf.find(a[i]) == uf.find(b[i])){
			ans[a[i]]--;
			ans[b[i]]--;
		}
	}
	
	zep(i, 0, k){
		cin >> c >> d;
		if(uf.find(c) == uf.find(d)){
			ans[c]--;
			ans[d]--;
		}
	}
	
	rep(i, 1, n){
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a,b,c,d;
  d = n%10;
  n /= 10;
  c = n%10;
  n /= 10;
  b = n%10;
  a = n/10;
  
  int answer=0;
  char op1,op2,op3;
  
  for(int i=0; i<8; i++){
    int tmp=a;
    if(i>>0&1){
      tmp += b;
      op1 = '+';
    }else{
      tmp -= b;
      op1 = '-';
    }

    if(i>>1&1){
      tmp += c;
      op2 = '+';
    }else{
      tmp -= c;
      op2 = '-';
    }

    if(i>>2&1){
      tmp += d;
      op3 = '+';
    }else{
      tmp -= d;
      op3 = '-';
    } 

    if(tmp == 7){
      cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
      break;
    }
  }  
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int,input().split()))
 
ans = []
while B:
    for i,a in reversed(list(enumerate(B))):
        if i+1 == a:
            ans.append(a)
            del B[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')

Measured memory_bytes: 3060